Command Button

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
 
R

Reggie

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top