Access Code

Associate
Joined
10 Jan 2006
Posts
483
I have writtien a piece of code in MS access in order to create payments for a specific month. The proble i have with it is that my validation rule does not seem to work and when i leave the date field blank it does nothing, can anyone find the bug?

Private Sub cmdMakeSubs_Click()
Dim db As Database
Dim Amount As Currency

Set db = CurrentDb
Dim rcdsSubsDue As DAO.Recordset
Dim rcdspayments As DAO.Recordset
Set rcdsSubsDue = db.OpenRecordset("qrySubsDue")
Set rcdspayments = db.OpenRecordset("tblPayments")

If txtDate = Empty Then
MsgBox "You must enter a date for this to work"
Exit Sub
End If

rcdsSubsDue.MoveFirst
Do Until rcdsSubsDue.EOF
rcdspayments.AddNew
rcdspayments("member ID") = rcdsSubsDue("member ID")
If rcdsSubsDue("status") = "J" Then Amount = 100 Else Amount = 300
rcdspayments("Amount") = Amount
rcdspayments("Date Due") = txtDate
rcdspayments.Update



rcdsSubsDue.MoveNext
Loop
End Sub
 
isnt this -
If txtDate = Empty Then

wrong? as empty hasnt been set as a variable or is a object?
what thrash posted "should" work or atleast thats what i'd have done (hnd visual basic novice)
 
txtDate is a field in a record set so it does not have a text property, all you need to do is test the field itself, i.e. txtdata against the empty string "". You could have course define a variable called empty and assign it to "" then do the test that way.
 
Are you testing to see if a text box has been filled in?

If so this should work;

txtDate.SetFocus
If txtDate.Text = "" Then
MsgBox "You must enter a Name for this to work"
End If

etc

Or are you testing for an empty record in the database?

Mel P
 
need one more piece of help ive tried various bits of code but can not seem to get it right.
I need to set a validation rule so when something in the wrong format is entered a message box comes up saying this is in the worng format.
Any tips?
 
Back
Top Bottom