Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Microsoft Access Module (Code) 1

Status
Not open for further replies.

hwmueller

Technical User
Jan 16, 2001
155
Hi

I am a new user of Microsoft Access and have a question concerning the use of module code. I am trying to program a button in a form which allows the user to see a preview of a report of that form. The problem is that I can only get the button to show all pages in that report instead of the one actually being viewed. The problem I think lies with the data type being used by the primary key i.e 'text' and not 'AutoNumber'. The code I have written so far is as follows:

Private Sub Customer_Sheet_Preview_Click()
On Error GoTo Err_Customer_Sheet_Preview_Click
If IsNull(Me![Customer ID]) Then
MsgBox "Please enter customer details before clicking preview."
Else
DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70
DoCmd.OpenReport "Customer_Sheet_Preview", acPreview, , "[Customer ID] = " & [Customer ID]
End If

Exit_Customer_Sheet_Preview_Click:
Exit Sub

Err_Customer_Sheet_Preview_Click:
MsgBox Err.Description
Resume Exit_Customer_Sheet_Preview_Click
End Sub

When running the code I get the following error message:

"Data type mismatch in criteria expression".

What is wrong??!! Thanks for your help in advance!

Hans Mueller
 
Hans,

On what line are you getting the error?

What is the data type of the [customer id] field? If it is text, you need

DoCmd.OpenReport "Customer_Sheet_Preview", acPreview, , "[Customer ID] = '" & [Customer ID] & "'"

Hope that helps.





Kathryn


 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top