Finding a Record in a Subform

J

Jack G

I have a Main Form with a subform (called "Subform") in it. The subform's
Source Object gets swapped depending on what button is clicked on the Main
Form.

I also have an unbound text box on the Main Form called [GoTo] where I want
to enter a "project number" and then have the subform go to that record. I
have the following for the AfterUpdate event of the [GoTo]textbox:

Dim stCurrentProject As String
stCurrentProject = [GoTo]
Me!Subform!ctlProjectNumber.SetFocus
DoCmd.FindRecord stCurrentProject, acEntire, False, , False, acCurrent, True

But the last line doesn't work, giving me an error that says, "...failed
because of an error in a FindRecord action argument. The code used to work
when the [GoTo] textbox was in the subform itself, but not now that it's out
in the main form.

Can anyone help me get this right?

Thanks,

Jack
 
G

Guest

Hi Jack,

I think that third line is incorrect, but I'm not sure.

Try this:

Me!subformCONTROLname.form!ctlProjectNumber

I never can remember if, between the subfrom control name and the 'form' you
need a !(bang) or .(dot).

See if that helps,
CW
 
J

Jack G

Thanks CW, but that doesn't seem to the problem -- the third line succeeds
in moving the focus to the desired control. It's the next line where things
go wrong.

Jack

Cheese_whiz said:
Hi Jack,

I think that third line is incorrect, but I'm not sure.

Try this:

Me!subformCONTROLname.form!ctlProjectNumber

I never can remember if, between the subfrom control name and the 'form' you
need a !(bang) or .(dot).

See if that helps,
CW

Jack G said:
I have a Main Form with a subform (called "Subform") in it. The subform's
Source Object gets swapped depending on what button is clicked on the Main
Form.

I also have an unbound text box on the Main Form called [GoTo] where I want
to enter a "project number" and then have the subform go to that record. I
have the following for the AfterUpdate event of the [GoTo]textbox:

Dim stCurrentProject As String
stCurrentProject = [GoTo]
Me!Subform!ctlProjectNumber.SetFocus
DoCmd.FindRecord stCurrentProject, acEntire, False, , False, acCurrent, True

But the last line doesn't work, giving me an error that says, "...failed
because of an error in a FindRecord action argument. The code used to work
when the [GoTo] textbox was in the subform itself, but not now that it's out
in the main form.

Can anyone help me get this right?

Thanks,

Jack
 
J

Jack G

Found my problem: I need to set the focus to the whole Subform control, not
the ctlPlrojectNumber control inside the subform.
 

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