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

Auto select report based on text item value 1

Status
Not open for further replies.

RnRExpress

Technical User
Oct 24, 2004
53
US
Ok, I'm back and in need of more wonderful help from you folks.

I have a command button that automatically selects the record I am on, and prints out a specific report.

Here is what I have. I have a database where I have a field called "Location ID". There are 5 options in this text box's value list. And I have this one report, which are all identical, except the heading part which prints out the location's name, address, phone number and hour of operations.

I have a button on the form, which runs this code:
Private Sub Command209_Click()
If Me.Dirty Then 'Save any edits.
Me.Dirty = False
End If

If Me.NewRecord Then 'Check there is a record to print
MsgBox "Select a record to print"
Else
strWhere = "[Record ID] = " & Me.[Record ID]
DoCmd.OpenReport "Report1", acViewNormal, , strWhere
End If
Me.[2nd Notice] = Date
End Sub

what I would like to have, if its possible, is after I select this command button to print this report, have the program look at the field "Location ID" and if it sees R123 (for example), it will print "Report1". But if it sees X456, then it knows to print "Report2", and on and on.

I was experimenting trying to add some If, Else liens in, but ended up messing it all up.

I'd appreciate any help folks!

Thanks,

RIchard
 
Can you please post some samples of "Location ID" values, and ALL the ReportX with the corresponding criteria.

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
PHV,

For example, I have these locations:

U066, U182, W331, W345, and W715.

And the five reports I have are named: 2nd_U066, 2nd_u182, 2nd_W331, 2nd_W345, and 2nd_W715.

As you can see, its a one to one correlation that will not vary.

Now, when entering data on my form, I have a text box, called "Location ID" with the five locations in a value list, and one of the 5 has to be selected.

Now I have the code from the above post, assigned to a command button on the form. I would like to be able to select that command button, and have the code automatically select and print 2nd_W331 because the "Location ID" is W331 on that particular record. If the Location ID is set to U066, then I wish to print 2nd_U066.

What these reports basically are, are form letters which values from the record I am printing from, fill in. But since each location has different addresses and such, I made this form letter and edited it and saved each location as a separate report.

What I do right now, is have 5 command buttons on my form. I simply click on the appropriate one to print out the report I need. But its a waste of form space having 5 buttons if I can get one button to do the same.

Richard
 
Something like this ?
strWhere = "[Record ID] = " & Me.[Record ID]
DoCmd.OpenReport "2nd_" & Me.[Location ID], acViewNormal, , strWhere

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
I will definately give that a try tomorrow and see if that works the magic. Thanks again for the awesome help, as always!

Richard
 
PHV,

Tried it out and worked like a charm. Thanks a million!

Richard
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top