Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

code for double click criteria

0 views
Skip to first unread message

Scott_Brasted via AccessMonster.com

unread,
Nov 25, 2009, 1:45:18 PM11/25/09
to
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
---------------------------------------------------
Private Sub txtDonorLastName_DblClick(Cancel As Integer)
ViewDonor
End Sub

--
Message posted via AccessMonster.com
http://www.accessmonster.com/Uwe/Forums.aspx/access-forms/200911/1

J_Goddard via AccessMonster.com

unread,
Nov 25, 2009, 2:09:28 PM11/25/09
to
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

--
John Goddard
Ottawa, ON Canada
jrgoddard at cyberus dot ca

Al Campagna

unread,
Nov 25, 2009, 2:12:40 PM11/25/09
to
Scott,
If ContributerID is numeric, try...
DoCmd.OpenForm "frmViewDonor", , , "[ContributorID] = " & Me.ContributorID
--
hth
Al Campagna
Microsoft Access MVP
http://home.comcast.net/~cccsolutions/index.html

"Find a job that you love... and you'll never work a day in your life."

"Scott_Brasted via AccessMonster.com" <u56211@uwe> wrote in message
news:9fa79a2172613@uwe...

Scott_Brasted via AccessMonster.com

unread,
Nov 25, 2009, 5:36:36 PM11/25/09
to
Thank you! It works a charm. I just learned something new. I really
appreciate the help.

Happy Thanksgiving.
Scott

J_Goddard wrote:
>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
>

--

Scott_Brasted via AccessMonster.com

unread,
Nov 25, 2009, 7:28:08 PM11/25/09
to
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 wrote:
>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
>

--

John_G via AccessMonster.com

unread,
Nov 25, 2009, 8:24:00 PM11/25/09
to
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 wrote:
>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
>

>>Hi -
>>
>[quoted text clipped - 25 lines]
>>> ViewDonor
>>>End Sub

--
John Goddard
E-Mail: jrgoddard AT cyberus DOT ca

Message posted via http://www.accessmonster.com

Scott_Brasted via AccessMonster.com

unread,
Nov 25, 2009, 10:38:14 PM11/25/09
to
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 Campagna wrote:
>Scott,
> If ContributerID is numeric, try...
>DoCmd.OpenForm "frmViewDonor", , , "[ContributorID] = " & Me.ContributorID

>> Greetings,
>>
>[quoted text clipped - 35 lines]
>> ViewDonor
>> End Sub

--
Message posted via http://www.accessmonster.com

J_Goddard via AccessMonster.com

unread,
Nov 26, 2009, 9:52:37 AM11/26/09
to
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,
>> If ContributerID is numeric, try...

>[quoted text clipped - 4 lines]
>>> ViewDonor
>>> End Sub

--

John Goddard
Ottawa, ON Canada
jrgoddard at cyberus dot ca

Message posted via http://www.accessmonster.com

Scott_Brasted via AccessMonster.com

unread,
Nov 26, 2009, 12:15:40 PM11/26/09
to
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 wrote:
>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]
>>>> ViewDonor
>>>> End Sub
>

--

J_Goddard via AccessMonster.com

unread,
Nov 26, 2009, 1:13:33 PM11/26/09
to
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

>>Hi -
>>
>[quoted text clipped - 15 lines]
>>>>> ViewDonor
>>>>> End Sub

--

John Goddard
Ottawa, ON Canada
jrgoddard at cyberus dot ca

Message posted via AccessMonster.com
http://www.accessmonster.com/Uwe/Forums.aspx/access-forms/200911/1

0 new messages