Double click to Open Form

  • Thread starter Thread starter JJ
  • Start date Start date
J

JJ

I am trying to add a way for users to be able to double-
click a field on one form that will open another form that
contains more detailed information. Below is my code but
it's doing nothing.

Private Sub Text51_DblClick(Cancel As Integer)
On Error GoTo Err_Text51_DblClick

DoCmd.OpenForm "frmCoDetail", , , "[CompanyName]=" & Me!
[CompanyName]

Exit_Text51_DblClick:
Exit Sub

Err_Text51_DblClick:
MsgBox Err.Description
Resume Exit_Text51_DblClick

End Sub
 
Hi!

Is the name on the control that shows the companyname realy [CompanyName] ?
You shall refere to the control on the form (text control, combo control
etc.) not the field in the underlying recordset for the form.

It´s late so I´m not going to read this forum until tomorrow morning but
make sure that you use the name on the control not the field.

You will find the name on the control if you open up the form in design view
and set cursor (focus) on the textcontrol. Righgtclick and select
<Propertie>. Select tab <All> and go to the top. There you have the name on
the control!


// Niklas
 
Yes the name of the control was CompanyName. I changed it
to txtCompany and changed the code to
DoCmd.OpenForm "frmCoDetail", , , "[CompanyName]=" & Me!
[txtCompanyName] and now I'm getting am prompted for
parameter value. If I leave it blank it opens the form to
but it is filtered and no records showing. If I enter a
Company Name I get a runtime 2501 error and form is not
opened. What simple thing am I getting wrong?
-----Original Message-----
Hi!

Is the name on the control that shows the companyname realy [CompanyName] ?
You shall refere to the control on the form (text control, combo control
etc.) not the field in the underlying recordset for the form.

It´s late so I´m not going to read this forum until tomorrow morning but
make sure that you use the name on the control not the field.

You will find the name on the control if you open up the form in design view
and set cursor (focus) on the textcontrol. Righgtclick and select
<Propertie>. Select tab <All> and go to the top. There you have the name on
the control!


// Niklas


"JJ" <[email protected]> skrev i meddelandet
I am trying to add a way for users to be able to double-
click a field on one form that will open another form that
contains more detailed information. Below is my code but
it's doing nothing.

Private Sub Text51_DblClick(Cancel As Integer)
On Error GoTo Err_Text51_DblClick

DoCmd.OpenForm "frmCoDetail", , , "[CompanyName]=" & Me!
[CompanyName]

Exit_Text51_DblClick:
Exit Sub

Err_Text51_DblClick:
MsgBox Err.Description
Resume Exit_Text51_DblClick

End Sub


.
 
Try this: to populate the form your trying to open make the forms record source based on the value from the calling for

on the form field that you double click (calling form)

DoCmd.OpenForm "frmCoDetail

on the form that you want to open (formed being called):

Private Sub Form_Open(Cancel As Integer

'!~~!~!~ Whatever the control source on your form i

me.[companyname].recordsource = Forms!(the name of form you doubleclicked on).companynam


End Su
 
JJ said:
I am trying to add a way for users to be able to double-
click a field on one form that will open another form that
contains more detailed information. Below is my code but
it's doing nothing.

Private Sub Text51_DblClick(Cancel As Integer)
On Error GoTo Err_Text51_DblClick

DoCmd.OpenForm "frmCoDetail", , , "[CompanyName]=" & Me!
[CompanyName]

Exit_Text51_DblClick:
Exit Sub

Err_Text51_DblClick:
MsgBox Err.Description
Resume Exit_Text51_DblClick

End Sub

If the CompanyName field is a text field, as seems likely, you'll need
to enclose the value in the where-condition argument in quotes. Try
this:

DoCmd.OpenForm "frmCoDetail", , , _
"CompanyName=" & _
Chr(34) & Me!CompanyName & Chr(34)

I remove the brackets because they aren't necessary in this case,
assuming the field and control names are as posted.
 
Back
Top