threeieng
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
If Not IsNull(Me.txtSearchNum) Then
Me!Child808.SetFocus
RunCommand acCmdRecordsGoToNew
Me!Child808!cmbJob = Me.txtSearchNum
End If
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,
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
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
ASKER
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
mx
What type of Control is "Child808"? Is is a Combo, Texbox, Subform, etc etc
ASKER
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.
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.
ASKER
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.Se tFocus
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
Me!Child808.SetFocus ' ** changed this
Me!Child808.Form.cmbJob.Se
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
ASKER
Same as before.
"Me.NewRecord is True no matter if the focus is in the new record or in an existing record."
"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
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Accepted own solution because other solutions did not work.
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