pr2-eugin
Super Moderator
- Local time
- Today, 20:27
- Joined
- Nov 30, 2011
- Messages
- 8,494
I have to monitor attendance of employees on a week by week basis. I have an (unbound) Form to input the number of hours to be input for agent. The table (AGENT_ATTENDANCE) has fields WK_NO(a week number), WK_Start_Date (probably the date of Monday), 5 individual day columns (represents 5 days of the week), AGENT_ID_fk.
I want to INSERT a new record if the agentID and WeekStartDate is not in the table, if that is available, I need it to UPDATE the specific hours for that specific day..
The problem is if I enter 08/10/2012 (8 -Oct- 2012) it switches the format from dd/mm/yyyy to mm/dd/yyyy on the Update/Insert statement.
* I have set the format of the table field and the control on the form as Short Date (whose format is dd/mm/yyyy).
* I used a variable declared as Date and assigned the control's value into the update query.
* I tried taking off the # symbols in the update Query then it stored the value (whatever the date was) to 30/12/1899
* I converted the # symbol to ' , it stores the value in the right format, but is not able to check/compare the date on a later stage..
my simple code is as follows..
This piece of code..
stores the right format, but when I try to do a DMax with this as criteria, it fails..
I did similar variations to the above code as I did for INSERT query. But no luck. Any pointers?? I have attached the mdb file..
WALK THROUGH for the form,
1. The Agent is selected from the LIST,
2. Day for which hours need to be added is selected from the Day comboBox,
3. Hours worked is added,
3. Update/Save is selected.
I want to INSERT a new record if the agentID and WeekStartDate is not in the table, if that is available, I need it to UPDATE the specific hours for that specific day..
The problem is if I enter 08/10/2012 (8 -Oct- 2012) it switches the format from dd/mm/yyyy to mm/dd/yyyy on the Update/Insert statement.
* I have set the format of the table field and the control on the form as Short Date (whose format is dd/mm/yyyy).
* I used a variable declared as Date and assigned the control's value into the update query.
* I tried taking off the # symbols in the update Query then it stored the value (whatever the date was) to 30/12/1899
* I converted the # symbol to ' , it stores the value in the right format, but is not able to check/compare the date on a later stage..
my simple code is as follows..
Code:
Dim dateVar As Date
dateVar = Me.WeekStDt_TxtBox
myQry = "INSERT INTO AGENT_ATTENDENCE(AGENT_ID_fk, WK_NO, WK_Start_Date) VALUES (88, 1, " & dateVar & ")"
[COLOR=Green]' Other combinations were...
' .... VALUES (88, 1, " & Me.WeekStDt_TxtBox & ")"
' .... VALUES (88, 1, " & CDate(Me.WeekStDt_TxtBox) & ")"
' .... VALUES (88, 1, #" & Me.WeekStDt_TxtBox & "#)"
' .... VALUES (88, 1, '" & Me.WeekStDt_TxtBox & "')"[/COLOR]
Code:
' .... VALUES (88, 1, '" & Me.WeekStDt_TxtBox & "')"
Code:
Nz(DMax("WK_NO", "AGENT_ATTENDENCE", "((AGENT_ID_fk = " & Me.Agent_List.Column(0) & ") AND (WK_Start_Date = " & Me.WeekStDt_TxtBox & " ))"), 0)
[COLOR=Green]'I did similar variations to the above code as I did for INSERT query. But no luck.[/COLOR]
WALK THROUGH for the form,
1. The Agent is selected from the LIST,
2. Day for which hours need to be added is selected from the Day comboBox,
3. Hours worked is added,
3. Update/Save is selected.