Application Defined or Object-Defined Error

FranD

Registered User.
Local time
Today, 18:50
Joined
Feb 29, 2000
Messages
32
I have two forms which are linked via the primary key ([Control#]. Users enter a Received Date in the main form and then later enter the Date Closed into the linked form. The main form is called LogBatch1 and the linked form is called frmCloseBatch. I'm trying to enter validation criteria in the Close Batch form to prevent users from entering a date that preceeds the date the batch was received. I wrote some code in the Before Update event of the frmCloseBatch - but I'm getting an error message "Application-defined or Object-defined error" (error 2465).

Here's the code:
Dim strMessage As String
Dim intOptions As Integer
Dim bytChoice As Byte
If CDate (DateClosed) < Form.LogBatch1.txtDateReceived then
strMessage = "....blah blah blah"
intOptions = vbOKCancel
bytChoice = MsgBox (strMessage, intOptions, "Invalid Date")
DateClosed.SetFocus
Cancel = True
End If
End Sub

Any suggestions...I'm really stumped!!!
 
I tried two variations on your code and was unable to reproduce that particular error. This code:

Private Sub Form_BeforeUpdate(Cancel As Integer)
Dim strMessage As String
Dim intOptions As Integer
Dim bytChoice As Byte
If CDate(Me!NewDate) < Me!OldDate Then
strMessage = "....blah blah blah"
intOptions = vbOKCancel
bytChoice = MsgBox(strMessage, intOptions, "Invalid Date")
NewDate.SetFocus
Cancel = True
End If
End Sub

which is yours with some name changes for my form, works well when both "NewDate" and "OldDate" are "date" fields. When I used a text field for the closure date, which it looks like you did in your code, it simply allows me to update or go to the next record without flinching. But I couldn't get the error. When I used a text field for the received date, it also works. Is there a reason your second date is a text field?

Matt
 
Matthew,
Thanks for your reply. To answer your question, the second date field is indeed a Date/time field. I simply referred to the control on the form instead of the field in the table - thinking that that was perhaps what was causing my initial error of "Data Type Mismatch. Maybe I should have given you my original code:

Private Sub Form_BeforeUpdate(Cancel As Integer)
Dim strMessage As String
Dim intOptions As Integer
Dim bytChoice As Byte
If CDate(DateClosed) < DLookup("[Received]", "LogBatch", "[Control#] = " & [Control#]) Then
strMessage = "blah, blah, blah"
intOptions = vbOKCancel
bytChoice = MsgBox(strMessage, intOptions, "Invalid Date")
DateClosed.SetFocus
Cancel = True
End If

Any ideas????? I thought this would be a straight forward code, since all I'm really doing is making sure that the date on the pop-up form is after the date on the main form (LogBatch1).

Thanks again!!!!!
 
I see two potential problems, although I am not sure that either would cause the error you describe.

If CDate(DateClosed) < DLookup("[Received]", "LogBatch", "[Control#] = " & [Control#]) Then

Question - Where does DateClosed come from. If it is a control and a form then you should reference it using the explicit path (Form!FrmName!DateClosed) or using the keyword Me!DateClosed

Suggestion - if Control# holds a date then you might try using CDate on it, so that you are comparing Date to Date.

Dim temp as Date
temp = DLookUp("[Received]", "LogBatch", "[Control#] = " & [Control#])

temp = cdate(temp)
if cdate(me.dateclosed) = temp then
blah blah blah

Or you could try enclosing the Date value in #' in order to designate it as a date.

If CDate(DateClosed) < DLookup("[Received]", "LogBatch", "[Control#] = #" & [Control#] &"#") Then

Hope this is of some use...
Chris
 

Users who are viewing this thread

Back
Top Bottom