I'm really hoping this will be the last problem I run into because I don't have much hair left to pull out! :)
I have a form that the user will enter a census date (indexed field) and a census into. I'm indexing the census date because I don't want duplicate entries.
When the user opens the frmCensus and tries to enter a date, I've implemented code that fires when the user selects a submit button that should check to see if the date has already been entered or not. If the answer is yes, msgbox pops up, clears all fields, and sets the focus on the date field. If the answer is no, the record is saved.
However, things aren't working out the way I had hoped and I think it's because there's an error with the Dlookup function I've used. Here's the current code:
Expand|Select|Wrap|Line Numbers
- Private Sub cmdSubmit_Click()
- Dim varCensusDate
- varCensusDate = Me.CensusDate
- If IsNothing(varCensusDate) Then
- MsgBox "Date field cannot be blank", vbExclamation, "Null value"
- Exit Sub
- End If
- If IsNothing(Me.Census) Or Me.Census = 0 Then
- MsgBox "Census cannot be blank or have a zero value", vbExclamation, "Null Value"
- Exit Sub
- End If
- If Not IsNothing(DLookup("CensusDate", "tblCensus", varCensusDate)) Then
- MsgBox "A census value has already been entered for this date", vbInformation, "Duplicate Entry"
- If (Me.Dirty = True) Then
- Me.Undo
- End If
- Me.CensusDate.SetFocus
- Exit Sub
- End If
- End Sub
Any ideas?
Thanks,
beacon