Solved

Continuous form navagation in Access 2010

Posted on 2011-03-10
14
344 Views
Last Modified: 2012-05-11
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
0
Comment
Question by:threeieng
  • 7
  • 5
  • 2
14 Comments
 
LVL 75
ID: 35103497

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
0
 

Author Comment

by:threeieng
ID: 35103743
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,
0
 
LVL 75
ID: 35103834
"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
0
Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

 

Author Comment

by:threeieng
ID: 35104040
Me.NewRecord is True no matter if the focus is in the new record or in an existing record.
0
 
LVL 75
ID: 35106194
Sorry ... but that's not really possible.  Something else is going on ...

mx
0
 
LVL 84
ID: 35107767
What type of Control is "Child808"? Is is a Combo, Texbox, Subform, etc etc
0
 

Author Comment

by:threeieng
ID: 35107830
It is a subform.
0
 
LVL 84
ID: 35107958
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.


0
 

Author Comment

by:threeieng
ID: 35108505
When I add Form to the .SetFocus I get an error that says "There is an invalid method in an expression."
0
 
LVL 75
ID: 35109772
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
0
 

Author Comment

by:threeieng
ID: 35127850
Same as before.
"Me.NewRecord is True no matter if the focus is in the new record or in an existing record."
0
 
LVL 75
ID: 35129899
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:
http://www.experts-exchange.com/Community_Support/General/A_2790-How-do-I-attach-a-file-at-Experts-Exchange.html

mx
0
 

Accepted Solution

by:
threeieng earned 0 total points
ID: 35130577
I figured out a way to accomplish what I wanted.  I simply read the value from the combo box and store it to a temporary variable.  If the temp value is null then I move to the new record.  Works just fine.

Thanks for all the input.
0
 

Author Closing Comment

by:threeieng
ID: 35170933
Accepted own solution because other solutions did not work.
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A simple tool to export all objects of two Access files as text and compare it with Meld, a free diff tool.
Preparing an email is something we should all take special care with – especially when the email is for somebody you may not know very well. The pressures of everyday working life stacked with a hectic office environment can make this a real challen…
Basics of query design. Shows you how to construct a simple query by adding tables, perform joins, defining output columns, perform sorting, and apply criteria.
What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA code.

837 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question