GoToRecord, but object isn't open

B

bw

"CarULineNum" is an unbound control in a subform frmCarRental. I can set
the value of the control as follows:
Forms![MakeTravelRequest]![frmCarRental]![CarULineNum] = 1
This works fine.

I want to now make the subform display the first record, so I use the
following code:
DoCmd.GoToRecord acDataForm, "frmCarRental", acFirst

With this code I get the following error, and description:
Error Number: 2489
Error Description: The object 'frmCarRental' isn't open.

How do I "reset" the subform frmCarRental to the first record?

Thanks,
Bernie
 
S

Stefan Hoffmann

hi,
"CarULineNum" is an unbound control in a subform frmCarRental. I can set
the value of the control as follows:
Forms![MakeTravelRequest]![frmCarRental]![CarULineNum] = 1
This works fine.
I want to now make the subform display the first record, so I use the
following code:
DoCmd.GoToRecord acDataForm, "frmCarRental", acFirst
You have to set the focus to your subform befor callinf GoToRecord:

Forms![MakeTravelRequest]![frmCarRental]![CarULineNum].SetFocus
DoCmd.GoToRecord acDataForm,,acFirst


mfG
--> stefan <--
 
B

bw

Thanks for your help Stefan, but I'm still getting the same error message
after setting the focus as you suggesed.

I have used both of the following, which produce the same error:
DoCmd.GoToRecord acDataForm, "frmCarRental", acFirst
DoCmd.GoToRecord acDataForm, "Forms![MakeTravelRequest]!frmCarRental]",
acFirst

Any other ideas?
Bernie

Stefan Hoffmann said:
hi,
"CarULineNum" is an unbound control in a subform frmCarRental. I can set
the value of the control as follows:
Forms![MakeTravelRequest]![frmCarRental]![CarULineNum] = 1
This works fine.
I want to now make the subform display the first record, so I use the
following code:
DoCmd.GoToRecord acDataForm, "frmCarRental", acFirst
You have to set the focus to your subform befor callinf GoToRecord:

Forms![MakeTravelRequest]![frmCarRental]![CarULineNum].SetFocus
DoCmd.GoToRecord acDataForm,,acFirst


mfG
--> stefan <--
 
S

Stefan Hoffmann

hi Bernie,
I have used both of the following, which produce the same error:
DoCmd.GoToRecord acDataForm, "frmCarRental", acFirst
DoCmd.GoToRecord acDataForm, "Forms![MakeTravelRequest]!frmCarRental]",
acFirst
You have to set the focus to your subform befor calling GoToRecord:
Forms![MakeTravelRequest]![frmCarRental]![CarULineNum].SetFocus
DoCmd.GoToRecord acDataForm,,acFirst
The lines above are two separate lines of code. You can't use the
subform reference in the DoCmd.GoToRecord.


mfG
--> stefan <--
 
B

bw

I'm sorry Stefan, but I'm not understanding.

Forms![MakeTravelRequest]![frmCarRental]![CarULineNum].SetFocus
DoCmd.GoToRecord acDataForm, ,acFirst

If I use this exact code above, then I get error 2493 "This action requires
an Object Name argument".
If I put the Object Name argument (frmCarRental) between the commas, then I
get the original error 2489 "The object 'frmCarRental' isn't open.

Bernie

Stefan Hoffmann said:
hi Bernie,
I have used both of the following, which produce the same error:
DoCmd.GoToRecord acDataForm, "frmCarRental", acFirst
DoCmd.GoToRecord acDataForm, "Forms![MakeTravelRequest]!frmCarRental]",
acFirst
You have to set the focus to your subform befor calling GoToRecord:
Forms![MakeTravelRequest]![frmCarRental]![CarULineNum].SetFocus
DoCmd.GoToRecord acDataForm,,acFirst
The lines above are two separate lines of code. You can't use the subform
reference in the DoCmd.GoToRecord.


mfG
--> stefan <--
 
S

Stefan Hoffmann

hi,
I'm sorry Stefan, but I'm not understanding.
I see, wasn't exactly what i wanted to write.
Forms![MakeTravelRequest]![frmCarRental]![CarULineNum].SetFocus
DoCmd.GoToRecord acDataForm, ,acFirst
Use

Me![SubFormControl].SetFocus
DoCmd.GoToRecord , , acFirst

instead.

mfG
--> stefan <--
 
B

Brian Bastl

You should only set focus to the subform control (the subform control name
and subform name may be different) if the main form is not on a new record,
otherwise you run the risk of you and/or your users entering orphaned
records. So in addition to what Stefan wrote, I'd check whether there is a
corresponding "Parent" record.

Private Sub Form_Current() 'main form
If Not Me.NewRecord Then
Me!frmCarRental.SetFocus
DoCmd.GoToRecord ,, acFirst
DoCmd.GoToControl "CarULineNum"
End If
End Sub

Private Sub frmCarRental_Enter()
If Not Me.NewRecord Then
DoCmd.GoToRecord , , acFirst
DoCmd.GoToControl "CarULineNum"
Else
'set focus to a control on main form
End If
End Sub

HTH,
Brian
 
B

bw

Same thing!

DoCmd.GoToRecord, , acFirst
This line of code requires an Object Name argument

Bernie


Stefan Hoffmann said:
hi,
I'm sorry Stefan, but I'm not understanding.
I see, wasn't exactly what i wanted to write.
Forms![MakeTravelRequest]![frmCarRental]![CarULineNum].SetFocus
DoCmd.GoToRecord acDataForm, ,acFirst
Use

Me![SubFormControl].SetFocus
DoCmd.GoToRecord , , acFirst

instead.

mfG
--> stefan <--
 
B

Brian Bastl

Bernie

Instead of Me!.... try typing Me. which will then activate Intellisense.
Scroll down until you find a reference to your subform control name. I
suspect that your subform name <> subform control name.

Brian


bw said:
Same thing!

DoCmd.GoToRecord, , acFirst
This line of code requires an Object Name argument

Bernie


Stefan Hoffmann said:
hi,
I'm sorry Stefan, but I'm not understanding.
I see, wasn't exactly what i wanted to write.
Forms![MakeTravelRequest]![frmCarRental]![CarULineNum].SetFocus
DoCmd.GoToRecord acDataForm, ,acFirst
Use

Me![SubFormControl].SetFocus
DoCmd.GoToRecord , , acFirst

instead.

mfG
--> stefan <--
 
B

bw

Stefan

I'm not sure what's going on now. The following is the code I'm now using
(according to your suggestion) and IT WORKS!!!

Forms![MakeTravelRequest]![frmCarRental]![CarULineNum] = 1
Forms![MakeTravelRequest]![frmCarRental].SetFocus
DoCmd.GoToRecord , , acFirst

While I can't guarantee it, I'm sure this was the same code I was using
previously, that didn't work. But now it does?!?!

I really appreciate your help. Thanks again!

Bernie

Stefan Hoffmann said:
hi,
I'm sorry Stefan, but I'm not understanding.
I see, wasn't exactly what i wanted to write.
Forms![MakeTravelRequest]![frmCarRental]![CarULineNum].SetFocus
DoCmd.GoToRecord acDataForm, ,acFirst
Use

Me![SubFormControl].SetFocus
DoCmd.GoToRecord , , acFirst

instead.

mfG
--> stefan <--
 

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