Object Required Error - What's wrong with my code?

R

Richard Horne

I have the following code which when clicked on previews a report. The code
basically checks all required fields are filled in, if they are it bookmarks
the current record, then refreshes the set of fields and then displays the
report.

The problem is I always get an "object required" error message, but the
report is still displayed properly? :S

Private Sub View_Customer_Confirmation_Full_Click()
On Error GoTo Err_View_Customer_Confirmation_Full_Click

If IsNull(Me!OrderDate) Then
MsgBox "Please enter the date this order was placed. For today's date hold
down CTRL and press ;."
Me.Order_Entry_Complete = False
Exit Sub
End If

If IsNull(Me!HIE) Then
MsgBox "Please select the order type from the HIE drop down list."
Me.Order_Entry_Complete = False
Exit Sub
End If

If IsNull(Me!Contact) Then
MsgBox "Please enter the Wyedean Contact against this order."
Me.Order_Entry_Complete = False
Exit Sub
End If

If IsNull(Me!DeliveryTerms) Then
MsgBox "Please select the delivery terms against this order."
Me.Order_Entry_Complete = False
Exit Sub
End If

If IsNull(Me!CustomersOrderNumber) Then
MsgBox "Please enter the customers' order number."
Me.Order_Entry_Complete = False
Exit Sub
End If


Dim stDocName As String
Dim rst As DAO.Recordset
Dim lngID As Long

lngID = OrderNumber


Me.Requery

Set rst = Me.RecordsetClone

rst.FindFirst "[OrderNumber] = " & lngID
If Not rst.NoMatch Then
Me.Bookmark = rst.Bookmark
End If

rst.Close

Set rst = Nothing


stDocName = "Customer_Confirmation_Full"
DoCmd.OpenReport stDocName, acPreview, , "[OrderNumber] = " &
Me![OrderNumber]
rs.Close
Set rs = Nothing

Exit_View_Customer_Confirmation_Full_Cli:
Exit Sub

Err_View_Customer_Confirmation_Full_Click:
MsgBox Err.Description
Resume Exit_View_Customer_Confirmation_Full_Cli

End Sub
 
R

Rick Brandt

Richard said:
I have the following code which when clicked on previews a report.
The code basically checks all required fields are filled in, if they
are it bookmarks the current record, then refreshes the set of fields
and then displays the report.

The problem is I always get an "object required" error message, but
the report is still displayed properly? :S
[snip code]

You have two sets of...

rs.Close
Set rs = Nothing

....so the second rs.Close is pointing at an object that no longer exists.

Why do you Requery the form only to navigate back to the same record you were
just on? Seems completely unnecessary and inefficient.
 
S

Stefan Hoffmann

hi Richard,

Richard said:
The problem is I always get an "object required" error message, but the
report is still displayed properly? :S
Place Option Explicit as second line in your form module and you will be
enlightened.

There is an undeclared variable in your code.

mfG
--> stefan <--
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top