I am trying to print the current record in a report in access. I have looked in the helpfiles but they are not clear on how you are applying the filter to isolate the current record.
Hi mooneye,
Is the record based on a table with one or more primary keys, or not?
If it is, it should be fairly simple. Let's say your table's primary key is called "ID". Is your form bound to the table (or query)? If so, you should just be able to add the ID field to the form (if it isn't already there). If you don't want it to show, you can make it invisible. Make a note of the name of the control that holds this value. By default, it's called the same name as the field in the table, so "ID". It's good practice to preface textboxes with "txt", so if somebody else programmed the form with an existing textbox for ID, it may be called something like "txtID".
Now, create your report query. Do it exactly the same way you would normally, but create one criteria: the ID field should be equal to the following (assuming the form name is "frmMyForm" and the ID's textbox is called "txtID": Forms![frmMyForm]![txtID]
Note that this method will create a report that will only work without hitch when the form is open. Alternatively, you could have the report not filter on anything if the form is not open, but that would require going into code. Please let me know if you'd like instruction on doing that.
Hope that helps! Please let me know if you have any questions/problems. Katie
Hi! I'm currently studying the COM+ programming model. Hopefully YOU'RE having fun, which would make one of us..
Sorry - I just realized I was in the VBA forum, and not the Access - General Discussion forum. You probably wanted code, didn't you?
Here you go. Sorry about the lack of testing.. I don't really have good tables to test on at the moment. This, again, assumes the primary key is called "ID" and of type Long (the code is slightly different for strings), the form is called "frmMyForm", and the textbox's control is called "txtID":
Private Sub Report_Open(Cancel As Integer)
On Error GoTo Err_Report_Open
If IsNull(Form_frmMyForm.txtID.Value) Then
Me.Filter = ""
Me.FilterOn = False
Else
Me.Filter = "[ID] = " & Form_frmMyForm.txtID.Value
Me.FilterOn = True
End If
Exit_Report_Open:
Exit Sub
Err_Report_Open:
MsgBox Err.Description, , "Report_Open: " & Err.Number
Resume Exit_Report_Open
End Sub
Again, hope that helps! Katie
Hi! I'm currently studying the COM+ programming model. Hopefully YOU'RE having fun, which would make one of us..
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.