Command Button

  • Thread starter Thread starter Alison
  • Start date Start date
A

Alison

I have a Company main form with a Contacts subform which
only lists the name of the contacts for that company
(ie., Parent / Child). I have a command button where I
want to open the Contacts main form (which lists all
contact details) from the Company form and filter it to
show only the records of the particular company. Can
anyone help me with the code or macro for this to work

thanks
 
Alison, My subform is in datasheet view and I use the Doubl-Click event of
the Subform record and I also have a command button on my main form to open
a form based on the record my cursor is in on the subform.

'the doubl-click event in the subform
Private Sub Form_DblClick(Cancel As Integer)
Dim i As Long
i = Me.CompanyID
DoCmd.OpenForm "frmView", , , , , acWindowNormal, i
End Sub

'Here I placed a text box on my main form and set the control source to the
CompanyID in the subfrom like so:
=[Forms]![frmMain]![frmSub].Form!CompanyID
'That way as the user scrolls through the subform the CompanyID for the
current record will be in this text box

Private Sub cmdView_Click()
On Error GoTo Err_cmdView_Click
Dim i As Long
i = Me.txtCompanyID
DoCmd.OpenForm "frmDetailView", , , , , acWindowNormal, i
Me.Visible = False

Exit_cmdView_Click:
Exit Sub

Err_cmdView_Click:
MsgBox "Place curser in record to be viewed."
Resume Exit_cmdView_Click
End Sub
 
Back
Top