Link to home
Start Free TrialLog in
Avatar of threeieng
threeiengFlag for United States of America

asked on

Continuous form navagation in Access 2010

I have form with a subform set to continuous mode.  I have a second form that is a search form that the user uses to search and the searched number is stored in txtSearchNum.  This number is used to populate a row in the database.  The code below works as long as the new record does not have the focus.  If the focus is in the new record the program stops at the line RunCommand acCmdRecordsGoToNew.  Is there a way to check to see if the focus is in the new record so I can prevent this line from executing?

    If Not IsNull(Me.txtSearchNum) Then
        Me!Child808.SetFocus
        RunCommand acCmdRecordsGoToNew
        Me!Child808!cmbJob = Me.txtSearchNum
    End If
Avatar of DatabaseMX (Joe Anderson - Former Microsoft Access MVP)
DatabaseMX (Joe Anderson - Former Microsoft Access MVP)
Flag of United States of America image


Sure ... like so:

    If Not IsNull(Me.txtSearchNum) Then
        Me!Child808.SetFocus
       If Me.NewRecord = False Then RunCommand acCmdRecordsGoToNew
        Me!Child808!cmbJob = Me.txtSearchNum
    End If

mx
Avatar of threeieng

ASKER

When I tested the supplied statement it doesn't work.  My subform displays 8 records.  If the focus is in the new record it works like I want.  If the focus is in one of the 8 records, it just replaces that record.  I need the focus to shift to the new record before the update.

Thanks,
"Is there a way to check to see if the focus is in the new record"

Yes ... by using the NewRecord property of the Form to test if you are at the New Record position.  The reason you get the error is because you are at the New Record position ... and the DoCmd fails for that reason.

"before the update.'
What update are you referring to ?

mx
Me.NewRecord is True no matter if the focus is in the new record or in an existing record.
Sorry ... but that's not really possible.  Something else is going on ...

mx
What type of Control is "Child808"? Is is a Combo, Texbox, Subform, etc etc
It is a subform.
Try setting focus to the Subform, then to a CONTROL on that subform. For example, your subform contains a control named "cmbJob". Set the focus to that control:

Me!Child808.Form.SetFocus
Me!Child808.Form.cmbJob.SetFocus

If Me.NewRecord = False Then RunCommand acCmdRecordsGoToNew

Note also that you should refer to controls on your subform like this:

Me!Child808.FORM.cmbJob = Me.txtSearchNum

"Child808" is the name of your Subform CONTROL. That control contains a SourceObject (which is a Form), and you must refer to that Form in order to work with the Controls and such on that form.


When I add Form to the .SetFocus I get an error that says "There is an invalid method in an expression."
A variation on what LSM posted


Me!Child808.SetFocus  ' ** changed this

Me!Child808.Form.cmbJob.SetFocus

If Me.NewRecord = False Then RunCommand acCmdRecordsGoToNew

Note also that you should refer to controls on your subform like this:

Me!Child808.FORM.cmbJob = Me.txtSearchNum
Same as before.
"Me.NewRecord is True no matter if the focus is in the new record or in an existing record."
Can you:

1) Compact & Repair (*** to shrink the size),

2) Zip up the MDB (*** to further shrink the size)

3) Attach the file for upload here (using the 'Attach File function below) ... removing any sensitive data of course.

4**** And please give a clear explanation of exactly how to reproduce the problem or what you are trying to do.

How to upload:
https://www.experts-exchange.com/Community_Support/General/A_2790-How-do-I-attach-a-file-at-Experts-Exchange.html

mx
ASKER CERTIFIED SOLUTION
Avatar of threeieng
threeieng
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Accepted own solution because other solutions did not work.