code for double click criteria

  • Thread starter Scott_Brasted via AccessMonster.com
  • Start date
S

Scott_Brasted via AccessMonster.com

Greetings,

I am trying to get this piece of code to work. I want to double click a name
in a subform and have the record in another form open. tblContributors.
[ContributorID] is the name of the hidden primary key field of the table that
holds the data for the form I want to open. So I make a function named
ViewDonor and then call it in Sub txtDonorLastName_DblClick. I thought that
the DoCmd.OpenForm should work. Obviously I am wrong. I get an error that
says "variable not defined" and it highlights the second tblContributors.

Anyone know what I am doing wrong? Anyone but me not know what I am doing
wrong?

Thanks,
Scott

Option Compare Database
Option Explicit
--------------------------------------------------
Private Sub ViewDonor()
On Error GoTo Err_ViewDonor

DoCmd.OpenForm "frmViewDonor", , , "tblContributors.[ContributorID]=" &
tblContributors.ContributorID

Exit_ViewDonor:
Exit Sub

Err_ViewDonor:
MsgBox Err.Description
Resume Exit_ViewDonor
End Sub
 
J

J_Goddard via AccessMonster.com

Hi -

MS Access doesn't know what tblContributors is in that context - it is
trying to find a control or variable with that name, and it can't, hence the
error.

ContributorID must be in a control on the record (i.e. on the form) you are
double-clicking, though it can be hidden. Then, your criteria in the DoCmd.
OpenForm statement must reference that control, something like this:

DoCmd.OpenForm "frmViewDonor", , , "tblContributors.[ContributorID]=" & Forms!
Myform.ContributorID

or

DoCmd.OpenForm "frmViewDonor", , , "tblContributors.[ContributorID]=" & Me!
ContributorID

This assumes that the control name is ContributorID.

HTH

John





Scott_Brasted said:
Greetings,

I am trying to get this piece of code to work. I want to double click a name
in a subform and have the record in another form open. tblContributors.
[ContributorID] is the name of the hidden primary key field of the table that
holds the data for the form I want to open. So I make a function named
ViewDonor and then call it in Sub txtDonorLastName_DblClick. I thought that
the DoCmd.OpenForm should work. Obviously I am wrong. I get an error that
says "variable not defined" and it highlights the second tblContributors.

Anyone know what I am doing wrong? Anyone but me not know what I am doing
wrong?

Thanks,
Scott

Option Compare Database
Option Explicit
--------------------------------------------------
Private Sub ViewDonor()
On Error GoTo Err_ViewDonor

DoCmd.OpenForm "frmViewDonor", , , "tblContributors.[ContributorID]=" &
tblContributors.ContributorID

Exit_ViewDonor:
Exit Sub

Err_ViewDonor:
MsgBox Err.Description
Resume Exit_ViewDonor
End Sub
 
S

Scott_Brasted via AccessMonster.com

Thank you! It works a charm. I just learned something new. I really
appreciate the help.

Happy Thanksgiving.
Scott

J_Goddard said:
Hi -

MS Access doesn't know what tblContributors is in that context - it is
trying to find a control or variable with that name, and it can't, hence the
error.

ContributorID must be in a control on the record (i.e. on the form) you are
double-clicking, though it can be hidden. Then, your criteria in the DoCmd.
OpenForm statement must reference that control, something like this:

DoCmd.OpenForm "frmViewDonor", , , "tblContributors.[ContributorID]=" & Forms!
Myform.ContributorID

or

DoCmd.OpenForm "frmViewDonor", , , "tblContributors.[ContributorID]=" & Me!
ContributorID

This assumes that the control name is ContributorID.

HTH

John
Greetings,
[quoted text clipped - 32 lines]
ViewDonor
End Sub
 
S

Scott_Brasted via AccessMonster.com

Hi again,

Everything worked great until I changed the subform from a datasheet to a
continuous form. Now the first line works, but every line after that opens a
blank form (no detail section - formheader and form footer are there). Can I
not use a continuous form or do I need to change something?

Thanks,
Scott

J_Goddard said:
Hi -

MS Access doesn't know what tblContributors is in that context - it is
trying to find a control or variable with that name, and it can't, hence the
error.

ContributorID must be in a control on the record (i.e. on the form) you are
double-clicking, though it can be hidden. Then, your criteria in the DoCmd.
OpenForm statement must reference that control, something like this:

DoCmd.OpenForm "frmViewDonor", , , "tblContributors.[ContributorID]=" & Forms!
Myform.ContributorID

or

DoCmd.OpenForm "frmViewDonor", , , "tblContributors.[ContributorID]=" & Me!
ContributorID

This assumes that the control name is ContributorID.

HTH

John
Greetings,
[quoted text clipped - 32 lines]
ViewDonor
End Sub
 
J

John_G via AccessMonster.com

You shouldn't have to change anything; did you make sure to include
ContributorID as a (hidden) control on the continuous form, and if so, did
you bind it to the underlying table/query field?

If the above is OK, try putting a Msgbox call in the Double-click code just
before it opens the Contributor form, to verify what ContributorID is:

MsgBox "Contributor ID = " & me!ContributorID
docmd.openform.....

John






Scott_Brasted said:
Hi again,

Everything worked great until I changed the subform from a datasheet to a
continuous form. Now the first line works, but every line after that opens a
blank form (no detail section - formheader and form footer are there). Can I
not use a continuous form or do I need to change something?

Thanks,
Scott
[quoted text clipped - 25 lines]
 
S

Scott_Brasted via AccessMonster.com

Hello,
Sorry, that did not work. No errors and it compiled, but I get a blank detail
section after the first record.
I get a message box tellimg me what record number the reocrd is then it opens
the form. First record, correct, rest blank.

Here is what I have right now:

Any thoughts?
Best,Scott

Option Compare Database
Option Explicit
-----------------------
Private Sub ViewDonor()
On Error GoTo Err_ViewDonor
MsgBox "Contributor ID = " & Me!idContributorID
DoCmd.OpenForm "frmViewDonor", , , "[ContributorID] = " & Me.
idContributorID
Exit_ViewDonor:
Exit Sub
Err_ViewDonor:
MsgBox Err.Description
Resume Exit_ViewDonor
End Sub
----------------------------
Private Sub txtName_DblClick(Cancel As Integer)
ViewDonor
End Sub



Al said:
Scott,
If ContributerID is numeric, try...
DoCmd.OpenForm "frmViewDonor", , , "[ContributorID] = " & Me.ContributorID
Greetings,
[quoted text clipped - 35 lines]
ViewDonor
End Sub
 
J

J_Goddard via AccessMonster.com

Hi -

Do the ContributorID values displayed by the Message Box appear to be correct?
If they are, then that suggests that the problem is not with the form you are
double-clicking in, but there is a problem with frmViewDonor, or with the
query behind that form. For example - does the query behind frmViewDonor
have criteria in it? Is the data in the ContributorID field of that query
what you expect it to be? Is there any code in frmViewDonor that might affect
what records are seen?

These are the first places I would look for errors.

John




Scott_Brasted said:
Hello,
Sorry, that did not work. No errors and it compiled, but I get a blank detail
section after the first record.
I get a message box tellimg me what record number the reocrd is then it opens
the form. First record, correct, rest blank.

Here is what I have right now:

Any thoughts?
Best,Scott

Option Compare Database
Option Explicit
-----------------------
Private Sub ViewDonor()
On Error GoTo Err_ViewDonor
MsgBox "Contributor ID = " & Me!idContributorID
DoCmd.OpenForm "frmViewDonor", , , "[ContributorID] = " & Me.
idContributorID
Exit_ViewDonor:
Exit Sub
Err_ViewDonor:
MsgBox Err.Description
Resume Exit_ViewDonor
End Sub
----------------------------
Private Sub txtName_DblClick(Cancel As Integer)
ViewDonor
End Sub
Scott,
If ContributerID is numeric, try...
[quoted text clipped - 4 lines]
 
S

Scott_Brasted via AccessMonster.com

Ok, so many things seem to be going wrong that I decided to start almost from
the beginning. I took all code out of both forms. I checked the
idContributorID name of the hidden field. Checked the source code.

I put code for opening form WITHOUT CRITERIA back in. Worked fine. Put
criteria back in and got error that vb could not find the form referenced in
the code.

This all worked originally when subform was datasheet. Then changed form to
continuous for formatting purposes. Stopped working. Changed form back and it
went to hell.

All names are correct as far as I can tell. Here is what I have now:

Option Compare Database
Option Explicit
-----------------------
Private Sub ViewDonor()
On Error GoTo Err_ViewDonor

DoCmd.OpenForm "frmViewDonor", , , "tblContributors.[ContributorID]=" &
Forms!frmCampaignPledgeListingSubform.idContributorID

Exit_ViewDonor:
Exit Sub

Err_ViewDonor:
MsgBox Err.Description
Resume Exit_ViewDonor
End Sub
-----------------------
Private Sub Name_DblClick(Cancel As Integer)
ViewDonor
End Sub

Thanks again,
Scott

J_Goddard said:
Hi -

Do the ContributorID values displayed by the Message Box appear to be correct?
If they are, then that suggests that the problem is not with the form you are
double-clicking in, but there is a problem with frmViewDonor, or with the
query behind that form. For example - does the query behind frmViewDonor
have criteria in it? Is the data in the ContributorID field of that query
what you expect it to be? Is there any code in frmViewDonor that might affect
what records are seen?

These are the first places I would look for errors.

John
Hello,
Sorry, that did not work. No errors and it compiled, but I get a blank detail
[quoted text clipped - 31 lines]
 
J

J_Goddard via AccessMonster.com

Well, I'm mystified. I use the same technique as you are using - a double-
click to bring up a detail form - and it works fine. I can change it from
datasheet to continuous and back without a problem.

We are obviously missing something. I wish I could be more help - maybe
someone else has some ideas?

John



Scott_Brasted said:
Ok, so many things seem to be going wrong that I decided to start almost from
the beginning. I took all code out of both forms. I checked the
idContributorID name of the hidden field. Checked the source code.

I put code for opening form WITHOUT CRITERIA back in. Worked fine. Put
criteria back in and got error that vb could not find the form referenced in
the code.

This all worked originally when subform was datasheet. Then changed form to
continuous for formatting purposes. Stopped working. Changed form back and it
went to hell.

All names are correct as far as I can tell. Here is what I have now:

Option Compare Database
Option Explicit
-----------------------
Private Sub ViewDonor()
On Error GoTo Err_ViewDonor

DoCmd.OpenForm "frmViewDonor", , , "tblContributors.[ContributorID]=" &
Forms!frmCampaignPledgeListingSubform.idContributorID

Exit_ViewDonor:
Exit Sub

Err_ViewDonor:
MsgBox Err.Description
Resume Exit_ViewDonor
End Sub
-----------------------
Private Sub Name_DblClick(Cancel As Integer)
ViewDonor
End Sub

Thanks again,
Scott
[quoted text clipped - 15 lines]
 

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