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

Help!!!!!!!!!!!!!!!!!!!!!!!!11 3

Status
Not open for further replies.

jdwm2310

Technical User
Jul 26, 2001
396
US
Hi,

I created a form and on it I have added a combo box and a preview report command button. The combo box is linked to the report.
The problem is that I want to preview the report of the selected item on the combo box.
For example, if I select Joe Smith from the combo box and then click on the preview button I would like to view the report for Joe Smith, and so on.
I really need your help I would appreciate anything.

Thanks.
 
In your preview button, put this code, of course changing to your field names:

Dim strCriteria As String
strCriteria = "[name] = Forms![frmYourForm]![ComboBox]"
DoCmd.OpenReport "rptReport", acViewPreview, strCriteria
 
ok let me get this straight.
I go to the event procedure of the Preview button and erase everyting in the command and add this below:

Dim strCriteria As String
strCriteria = "[EmployeeName, SocialSecurityNumber] = Forms![SERP Distribution List]![ComboBox33]"
DoCmd.OpenReport "SERP Plan Report", acViewPreview, strCriteria

Am I doing something wrong???
 
If EmployeeName is what you're looking for, try:

strCriteria = "[EmployeeName] = Forms![SERP Distribution List]![ComboBox33].Column(0)"
 
Hi!

There are a few differences that you will need. Try the code below:

Dim strCriteria As String

strCriteria = "[EmployeeName] = '" & Forms![SERP Distribution List]![ComboBox33]
& "'"
DoCmd.OpenReport "SERP Plan Report", acViewPreview, ,strCriteria

The above code assumes that you are searching on the employee name and that the name is the first column of the combo box. Please note that it is usually better to search on the ID since names can be typed in wrong and therefore give you no match. If that is what you want then change EmployeeName to EmployeeID and add .Columns(1) after [ComboBox33]. Also note that there needs to be two commas between acViewPreview and strCriteria in the OpenReport method.

hth
Jeff Bridgham
 
jebry

I insert the coding but now when I select the name and click on preview I get a blank report........????
 
Hi!

I didn't think about it before but you may want to check the name of the combo box. I used ComboBox33 in my post because you had used it earlier, but this doesn't sound like a name you chose and the standard Access name would be Combo33. Of course, if that is the problem I would think that Access would ask you for the parameter? One question, what is the recordsource of the combo box? Have you set it up so the spelling of the names in the combo box match what you have in the table?

Jeff Bridgham
 
This is the info. I have in my ComboBox:
Control Source: Eployee Data
Row Source type: Table/Query
Row Source: SELECT DISTINCTROW [SERP Plan Information Query].[Employee Data] FROM [SERP Plan Information Query];
Co1umn Count: 1
I hope this is useful.
 
If you go into the On Click event for your print preview button, hit the ... button to bring up the Code Builder window, and paste in this logic, it should work:

Dim strCriteria As String
strCriteria = "[EmployeeName] = Forms![SERP Distribution List]![ComboBox33].Column(0)"
DoCmd.OpenReport "SERP Plan Report", acViewPreview, strCriteria

I've done this several times before, and it works great...

HTH
 
What am I doing wrong, please advise. I copy the code but what am I doing wrong....could it be the combo box???
 
Hi!

A couple of things that I noticed. One, the combo box is pulling from a field called Employee data and the report is searching a field called employeename. Are you sure these two fields are equivalent? Two, check the name of the control, the fields, etc. to make sure that there are no misspellings anywhere.

One last note, any text box or combo box where you are going to choose search criteria should probably not have a control source. This can cause corrupted data if it isn't handled correctly.

One last question. Are you still getting a blank report or are you getting some sort of error message?

hth
Jeff Bridgham
 
I'm not sure if my post will be more helpful than any of the others but here goes...

I, too, have a form that when an Employee is chosen from a combo box a report for that Employee will pop up when the command button is clicked...Here's the code that is on the On Click event...

Dim stDocName As String
Dim strCrit As String

stDocName = "Employee Training Record"
strCrit = "[Employee Name] = '" & Me.txtEmployee & "'"

DoCmd.OpenReport stDocName, acPreview, , strCrit
'The 'Employee Training Record' is the name of my report and [Employee Name] is the name of the textbox on that report that displays the (duh:))Employee Name

On the form I put a textbox (txtEmployee) that pulled the Employee name out of the combobox and displayed it, except that in the properties I made the textbox Not Visible so it looks like the only thing on the form is the combobox and the command button...This seemed to work better then trying to get the query to read from the combo box...it had something to do with the bound column in the combobox...My suggestion is to create the above mentioned textbox and put this code on the On Click event of your command button...I hope this helps you out....
 
I'm not sure if my post will be more helpful than any of the others but here goes...

I, too, have a form that when an Employee is chosen from a combo box a report for that Employee will pop up when the command button is clicked...Here's the code that is on the On Click event...

Dim stDocName As String
Dim strCrit As String

stDocName = "Employee Training Record"
strCrit = "[Employee Name] = '" & Me.txtEmployee & "'"

DoCmd.OpenReport stDocName, acPreview, , strCrit
'The 'Employee Training Record' is the name of my report and [Employee Name] is the name of the textbox on that report that displays the (duh:))Employee Name

On the form I put a textbox (txtEmployee) that pulled the Employee name out of the combobox and displayed it, except that in the properties I made the textbox Not Visible so it looks like the only thing on the form is the combobox and the command button...This seemed to work better then trying to get the query to read from the combo box...it had something to do with the bound column in the combobox...My suggestion is to create the above mentioned textbox and put this code on the On Click event of your command button...I hope this helps you out....
 
Danielle17,

i created the textbox. What do I do with the bound column in the combo box?
 
jebry,

I am getting the report but not for the person I select.
 
I don't believe you have to do anything with the bound column. I was just making reference to why my application wasn't working before I put the text box on there....

Have you tired it yet with the code? Do you get the right person??

 
Hi!

That may be an indication that the data has been corrupted. I think it is important to make your search combo box unbound (i.e. no control source). I don't know if that will take care of the problem, but I think you should try it.

Jeff Bridgham
 
I am not worthing, you guys are the best.
It worked it finally worked...Wow!!!!!!!!!!!!!! I can't believe it. Thanks a million!!!!!!!!!!:-D
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top