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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Opening report on a specific record

Status
Not open for further replies.

LauraJM

Technical User
Feb 11, 2003
5
GB
I have written the following code;

I have a combo box in a form which when I choose a name form the list, I want to open a report for that chosen person. I did this before on a simple report and tried to replicate for this report, but this report contains several subreports which all contain the primary key EMP_UID, but now when I run the same code that worked on the simple report all of my reports open not the report for the name I have chosen in my combo box.

Although the message box displays the EMP_UID for the person I have chosen, so I've picked it out from the form I just can't seem to refer to it when opening the form.

Can anyone tell me what I'm doing wrong?
Thankyou.

Private Sub Combo54_Change()
On Error GoTo Err_Command54_Click

Dim stDocName As String
Dim CurrentEmp As String

CurrentEmp = [Forms]![frm_Reports]![Combo54]

MsgBox CurrentEmp

DoCmd.GoToControl "EMP_UID1"
DoCmd.FindRecord CurrentEmp, acAnywhere, False, , , acAll, True

stDocName = "rpt1_EmployeeOuput"
DoCmd.OpenReport stDocName, acPreview

Exit_Command54_Click:
Exit Sub

Err_Command54_Click:
MsgBox Err.Description
Resume Exit_Command54_Click
End Sub
 
HI

Private Sub Combo54_AfterUpdate()
On Error GoTo Err_Command54_Click

Dim stDocName As String
Dim CurrentEmp As String

CurrentEmp = [Forms]![frm_Reports]![Combo54]

MsgBox CurrentEmp


stDocName = "rpt1_EmployeeOuput"
DoCmd.OpenReport stDocName, acPreview,,"[EMP_UID1] = " & Me.[EMP_UID1]

Exit_Command54_Click:
Exit Sub

Err_Command54_Click:
MsgBox Err.Description
Resume Exit_Command54_Click
End Sub

Regards

Ken Reay
Freelance Solutions Developer
Boldon Information Systems Ltd
Website needs upgrading, but for now - UK
 
Thankyou so much for getting back to me so quick.

I cut and pasted your code into my module and now I get an error message

" data type mismatch in criteria expression"

This I don't understand as EMP_UID is always text?

Any ideas?
 
Hi

OK, so if it is text you need

DoCmd.OpenReport stDocName, acPreview,,"[EMP_UID1] = '" & Me.[EMP_UID1] & "'"



Regards

Ken Reay
Freelance Solutions Developer
Boldon Information Systems Ltd
Website needs upgrading, but for now - UK
 
Thankyou so much, it works now without any errors.

Hope you have a nice Christmas.

Laura
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top