Heatshiver
Registered User.
- Local time
- Today, 17:56
- Joined
- Dec 23, 2011
- Messages
- 263
I have a piece of code that is meant to check both the Date and User ID to see if the User ID has already used that date. I noticed it doesn't work properly as I attempted to use a date that only a different user had already used, but the code came back with the message it should only show if the current user had used that date. This tells me that the User ID is not being properly checked along with the date. Here is the code:
Dim rs As Object
Set rs = CurrentDb.OpenRecordset("tblGenSum")
If rs.EOF And rs.BOF Then
MsgBox "No Record"
End If
Do While Not rs.EOF
If rs!Days = [Forms]![frmSTOTAct].Days And rs!UserID = [Forms]![frmSTOTAct].UserID Then
DoCmd.RunCommand acCmdUndo
MsgBox "This User ID has already used this date."
[Forms]![frmSTOTAct]![UserID] = ""
Me.Days.Value = ""
Exit Do
End If
rs.MoveNext
Loop
Set rs = Nothing
The other problem I am having is that a blank record is then created. I should not that I believe this is due to the subform... I have tried:
DoCmd.RunCommand acCmdUndo
This will delete the record in question entirely, and still add a blank record.
I have also tried:
rs.MoveLast
DoCmd.RunCommand acCmdSelectRecord
DoCmd.RunCommand acCmdDeleteRecord
But neither works and I still end up with a blank record without a Date or User ID. Any help would be much appreciated!
Dim rs As Object
Set rs = CurrentDb.OpenRecordset("tblGenSum")
If rs.EOF And rs.BOF Then
MsgBox "No Record"
End If
Do While Not rs.EOF
If rs!Days = [Forms]![frmSTOTAct].Days And rs!UserID = [Forms]![frmSTOTAct].UserID Then
DoCmd.RunCommand acCmdUndo
MsgBox "This User ID has already used this date."
[Forms]![frmSTOTAct]![UserID] = ""
Me.Days.Value = ""
Exit Do
End If
rs.MoveNext
Loop
Set rs = Nothing
The other problem I am having is that a blank record is then created. I should not that I believe this is due to the subform... I have tried:
DoCmd.RunCommand acCmdUndo
This will delete the record in question entirely, and still add a blank record.
I have also tried:
rs.MoveLast
DoCmd.RunCommand acCmdSelectRecord
DoCmd.RunCommand acCmdDeleteRecord
But neither works and I still end up with a blank record without a Date or User ID. Any help would be much appreciated!
Last edited: