Subform Navigation

J

Jagstrom

I have a Main form w/ subform

When opening any record on the Main, I would like to set focus to the
1st subform record with a null or "" value in "myfield"

any ideas?
 
K

Klatuu

Use the Form's Current event:

Me.SubCtl.Form.MyField.Setfocus
With Me.SubCtl.Form.RecordsetClone
.FindFirst "MyField IS NULL OR MyField = """""
If Not .Nomatch Then
Me.SubCtl.Form.Bookmark = .Bookmark
End If
End With
 
J

Jagstrom

Tried this:

Mainform = Leads
Subform = History


Private Sub Form_Current() ''MainForm Current

Me.History.Form.Disposition.SetFocus
With Me.History.Form.RecordsetClone
.FindFirst "MyField IS NULL OR MyField = """""
If Not .NoMatch Then
Me.History.Form.Bookmark = .Bookmark
End If
End With
End Sub

produced Compile error: Method or data member not found
 
B

Beetle

Presumably, the field in question is not actually named "MyField"
is it?

You need to use your actual field name in place of MyField in the
example that Dave provided
 
J

Jagstrom

lol, sorry i mean

Private Sub Form_Current()

Me.History.Form.Disposition.SetFocus
With Me.History.Form.RecordsetClone
.FindFirst "Disposition IS NULL OR Disposition = """""
If Not .NoMatch Then
Me.History.Form.Bookmark = .Bookmark
End If
End With
End Sub


same error though stopping on .History of 1st line

Me.History.Form.Disposition.SetFocus
 
B

Beetle

In that case you should check the name of your subform control
(the "window" that holds the subform). The name of the subform
control is usually, but not necessarily, the same as the name of the
subform itself. I suspect your subform control has a different name.
 
K

Klatuu

If History is the name of the form object, you reference is incorrect.
You do not use the name of the form object, but the name of the subform
control on the main form.
 
J

Jagstrom

ok, Corrected the naming issue
now the error is gone but the code runs though doing nothing

Disposition is in focus on the 1st record regardless of its value.
 
J

Jagstrom

ok, Naming corrected

Error resolved but code doesn't change anything.

Focus remains on Disposition field in History Subform regardless of
value

Note: Disposition is only control set to tab stop
 
J

Jagstrom

Solved,



Private Sub Form_Current() '' in Subform
History
DoCmd.GoToRecord , , acNewRec
End Sub


Thanks for your help
 
B

Beetle

Solved,

You might want to re-think that.

First, having the subform move to a new record is not what you said
you wanted in your original post (if that's what you wanted, and had
stated so, you would have received different advice).

Second, and more importantly, putting the command

DoCmd.GoToRecord , , acNewRec

in the Current event of your form is going to result in you never being
able to navigate to an existing record, because as soon as you do it's
going to immediately move back to a new record.
 
J

Jagstrom

Beetle,

Going to the first Null or empty string is nearly the same as acNewRec
for my purpose
it does remove the abilty to navigate to previous records, but its
seems the best I can come up with for now
 
K

Klatuu

Beetle, I have become very frustrated with this guy.
First, his questions are cryptic and incomplete.
He screws up doing what you recommend and gets irrated about it, then does
some bizzare thing like this.

I am done answering his posts.
 
Top