On Click Event in Report

bellemmar

Registered User.
Local time
Today, 15:39
Joined
Mar 9, 2011
Messages
64
I have a report called Policies and within the report is a field called Policy ID. I want to click on the Policy ID field in the report and have that policy's form automatically open. I had the following code:

Option Compare Database
Private Sub Policy_Number_Click()
DoCmd.OpenForm "Policy Management"
End Sub


Which opens the form but not to the specific policy record. Help please.
 
Still won't work. Either nothing happens or I get a syntax error or I get prompted to enter the parameter value (?)
 
Hard to fix without seeing your revised code. ;)

The parameter prompt would typically happen when the field name or form reference is spelled wrong, or doesn't exist.
 
I made the code as follows:
Option Compare Database
Private Sub ID_Click()
DoCmd.OpenForm "Policy Management", , , "ID = " & Me.ID
End Sub

My data field (and its label) are called ID (short & simple). But now when I click the field in the report, I get an "Enter Parameter Value" box that shows the specific ID number and then a type field below where it wants me to enter even though I've already identified the ID field in the code...
 
Is ID the name of the textbox? The parameter prompt is telling you that Access doesn't understand one of those. Make sure ID is a field in the record source of the form being opened as well. Can you post the db here?
 
Yes it's weird. The text box is called ID so I don't get it. I can't seem to upload it either but I've attached a screen print of the dialogue box. The AA0080 is the ID number of the specific policy I've clicked on in the report. Now if I type AA0080 into the dialogue box, it does what I want it to...but I would prefer if it just went there automatically.
 

Attachments

  • dbdb.JPG
    dbdb.JPG
    7.7 KB · Views: 208
That is a text value, so you'd want to use the syntax for text from that link.
 
The second example:

DoCmd.OpenForm "SecondFormName", , , "FieldName = '" & Me.ControlName & "'"
 
YAHOO!!! Thank you. I had tried this before but missed the first ' after the =
Awesome awesome awesome!! :)
 
Help again please!
I have a new (different) database and this code (above) that worked before won't work now??! I'm trying to click on a field in a report (field called Last Name) to open a second form called Contact Details.

DoCmd.OpenForm "Contact Details", , , "Last Name = '" & Me.Last_Name & "'"

This code isn't working at all in the new database though it worked in my last one. Ideas??
 
Because of the inadvisable space, you'd have to bracket the field:

[Last Name]
 
No problem. Those spaces always seem so pretty until you actually start coding. :p
 
HELP!
I'm using the same premise in a new database. I have the following code:

DoCmd.OpenForm "CurrentForms", , , "FormName = '" & Me.ID & "'"

[CurrentForms is the second form to be opened, FormName is the on-click (text) field in the report and ID is the control source (autonumber)].

But when I click the field in the report, it opens the second form to a blank record, not the specific record.
 
Is FormName a field in the form's source? You have the correct syntax for a text field there. Is ID the field in the report containing the value to filter on? Doesn't sound like it.
 

Users who are viewing this thread

Back
Top Bottom