SubForm to open Form based on Column

cstickman

Registered User.
Local time
Today, 09:40
Joined
Nov 10, 2014
Messages
109
Hey Everyone,

I created a subform based on a few columns. I then created a new form based on a query. I would like to click on one of the columns in the subform and have it open the form based on the item they clicked. Here is what I have done so far in attempts to get it to work:

Created a subform and placed it in a navigation form. While designing the subform I clicked on the column Audit ID and made it a hyperlink. In the onclick event I put the following code:

Code:
 Private Sub txtauditid_Click()
  
 On Error GoTo myError
  
 Dim varWhereClause As String
 varWhereClause = "Audit ID = '" & Me.txtauditid & "'"
 DoCmd.OpenForm "frmcontacts", , , varWhereClause
  
 leave:
Exit Sub
  
 myError:
MsgBox Error$

 Resume Next
  
End Sub

On the form frmcontacts I have the data record source set to a query. Then the text boxes on the form are linked to the fields based on the query. In the query in the Audit ID column under criteria I have txtauditid. I named it that because the first field on the frmcontacts is txtauditid. I feel as if I am missing something with passing the variable from the subform to the form frmcontacts.

So I am not sure what to change or where to go from this point.
 
Nevermind - I just figured it out. I guess walking away from it did the trick. I added to the query [Audit ID] and made the following changes in the code:

Code:
On Error GoTo myError
  
 Dim varWhereClause As String
  
 varWhereClause = "[Audit ID] = '" & Me![Audit ID] & "'"
  
 DoCmd.OpenForm "frmcontacts", , , varWhereClause
  
 leave:
Exit Sub
  
 myError:
MsgBox Error$

 Resume Next
 

Users who are viewing this thread

Back
Top Bottom