jarheadjim
08-23-2002, 03:35 PM
I have placed a command button on a form to open a report, but rather than show me just the information on that form, it gives me every record on the table. How do I make it just show the current information?
thanks
Travis
08-23-2002, 04:30 PM
When you do the Open Report code pass a Where condition with it to limit the report.
Example:
DoCmd.OpenReport "Report Name", acViewPreview, , "[MyID]=" & Me.[IDField]
jarheadjim
08-26-2002, 08:59 AM
I'm afraid I don't understand, what is [myid] in the example? Wouldn't this prompt you for input?
Pat Hartman
08-26-2002, 12:10 PM
MyID needs to be replaced with the column name of your unique id field. IDField needs to be replaced with the control name of the form field that contains the unique id.
"[MyID]=" & Me.[IDField] will be used as a Where clause to filter the recordset of the report.
jarheadjim
08-26-2002, 01:43 PM
let me see if i have this. I have it using an autonumber to be the primary key. this field is called [ReqNum]. so [myid]=[ReqNum], but what does [idfield]= ?, the name of the form that contains the field in question? sorry, i'm just not overly familiar with the lingo of database's. thanks for the help so far.
Travis
08-26-2002, 01:59 PM
let me see if i have this. I have it using an autonumber to be the primary key. this field is called [ReqNum]. so [myid]=[ReqNum], but what does [idfield]= ?, the name of the form that contains the field in question? sorry, i'm just not overly familiar with the lingo of database's. thanks for the help so far.
[MyId] = the Field Name in the Query/Table
[Idfield] =[The Name of the Field with the ReqNum Value in it]
Me = the Current form that the code is on. It is a substitute for "Forms![Your Form Name]"
DoCmd.OpenReport "Report Name", acViewPreview, , "[ReqNum]=" & Me.[The Name of the Field with the ReqNum Value in it]
jarheadjim
08-26-2002, 02:07 PM
Got it! I think what was throwing me off was that [myid] & [idfield] happen to be the exact same thing in my case. It works fine now. Thank you all for your patience.