Hey guys does anyone here knows what is the code for inserting the current day in a form? I'm creating an Employee Monitoring System. I have here a part of the codes of my program

Private Sub Command1_Click()
If Text1.Text = "2036251" Then
Adodc1.RecordSource = "select * from Table4 where Employee_ID= 2036251"
Adodc1.Refresh
Adodc1.Recordset.Fields("Time- In") = Time
Adodc1.Recordset.Fields("Date Log") = Date
Adodc1.Recordset.Fields("Day") = Day
Adodc1.Recordset.Update
End If

The code above generates an error and I think it is because of the line Adodc1.Recordset.Fields("Day") = Day. The problem is that I don't know what is the right code for that. The logic of my program is that once you typed in your employee_id number, the database should be updated. The database should display the current time, date and day of your login. Please help me. Thanks in advance :)

Not quite sure what you're asking for here. Do want the day of the week as a word (e.g. "Monday", "Thursday", etc.) or a day number (Sunday = 1, Monday = 2, etc.)? Day of the month?

Anyway, the thing you should look into is the FORMAT statement. Here's a sample piece of code that will give you today's date's day-of-week as a word:

Me.txtDay = Format(Now, "dddd") ' result gives "Monday"  if you run it right now '

Once you familiarize yourself with this statement, then look in the VB help file for the section "User-Defined Date/Time Formats (Format Function)". This has a list of the different formats you can use if the above scenario doesn't fit what you want to achieve.

Good luck! Hope this helped!

This is not normalised properly, Time, Date and Day should all be housed in the one field using a type of Date/Time. When you display them you can choose to display the one field three times for each of the values.

Thank you man! I already corrected it cheers!

hi, maybe my problem relates with this one.
im having trouble with my date, i want to record date only once in a day.but my code doesnt function. can anyone help me please?i ned it in our attendance checking once in a day.

Sub search()
'search if id registered
With ado
    .ConnectionString = connectdb
    .RecordSource = "Select * from info where id = '" & Text2 & "'"
    .Refresh
    If .Recordset.RecordCount > 0 Then
    Text3 = .Recordset!id
    Text4 = .Recordset!fname
    Text5 = .Recordset!lname
    Text6 = Date
'goto save record
    Call add
Public Sub add()
'save record
adoadd.Refresh
    If Text2.Text = adoadd.Recordset.Fields("date") Then
     MsgBox "duplicate date", vbInformation, "invalid"
     Text2 = ""
     Text3 = ""
     Text4 = ""
     Text5 = ""
     Text6 = ""
     Else
    With adoadd.Recordset
    .AddNew
    !id = Text3
    !First_Name = Text4
    !Last_Name = Text5
    !Date = Text6
    .Update
    MsgBox " save", vbInformation, "Done"
Text2 = ""
Text3 = ""
Text4 = ""
Text5 = ""
Text6 = ""
End With
End If
DataGrid1.Refresh
End Sub

Bold Text Here

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.