Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Jump to "New Record" in Subform 1

Status
Not open for further replies.

iamchemist

Programmer
Mar 2, 2009
73
US
I am a newbie to Access. I have a subform within a main form. I want to use the subform for data entry.

I would like for the subform to initially come up with the cursor on the last record, or on a blank field just below the last record, so that the user will be imediately in position to enter a "New Record".

I have tried creating an "OnEnter" Procedure with the code:

DoCmd.GoToRecord , , acLast

But the subform still starts out with the first record, and not the last record. It seems to ignore my VBA command.
 
Try this in the "OnOpen" event instead of OnEnter Docmd.GoToRecord acForm, "YourSubFormName", acNewRec
 
How are ya iamchemist . . .

In the [blue]On Load[/blue] event of the subform:
Code:
[blue]   if not me.NewRecord then docmd.RunCommand acCmdRecordsGoToNew[/blue]
[blue]Your Thoughts? . . .[/blue]

See Ya! . . . . . .

Be sure to see thread181-473997 [blue]Worthy Reading![/blue] [thumbsup2]
Also faq181-2886 [blue]Worthy Reading![/blue] [thumbsup2]
 
Hi Bubba100,

Thanks a lot for your reply. Can you please clarify - are you talking about the "OnOpen" Event for the main form or for the subform, in your reply?

Thanks again,

Ron
 
Bubba100 and TheAceMan1:

I did try both of your suggestions (bubba100 - did try the subform), but neither one resulted in the cursor being in the "new record" posibion in the subform, either when the main form was opened or when I clicked on the subform.

Other ideas?

Ron
 
iamchemist . . .

So sorry.[blush] For the docmd method used [blue]the subform has to have the focus![/blue] So remove the previous code and in the mainforms [blue]On Open[/blue] event, copy/paste the following:
Code:
[blue]   [[purple][B][I]subFormName[/I][/B][/purple]].SetFocus
   If Not Me.NewRecord Then DoCmd.RunCommand acCmdRecordsGoToNew[/blue]
[blue]Your Thoughts? . . .[/blue]

See Ya! . . . . . .

Be sure to see thread181-473997 [blue]Worthy Reading![/blue] [thumbsup2]
Also faq181-2886 [blue]Worthy Reading![/blue] [thumbsup2]
 
Hi Again TheAceMan1,

Thanks for your help, but somehow this is not working.

So far as I can tell, my subform has been given the name:
"tbl_Combined_Form subform_Ron", and even inserting the initial line of your suggested code - see below:

Private Sub Form_Load()
[tbl_Combined subform_Ron].SetFocus
End Sub

Results in an error and yields the normal "End" "Debug" window, which says that Access can't fine the field that is referred to. Could this be some sort of syntax problem? It seems to have to do with the fact that this is a subform that I am dealing with.

Thanks again for the help,

Ron

 
iamchemist . . .

Open the subform from the forms window. Then call up the properties window. Post back what the Name property saids.

See Ya! . . . . . .

Be sure to see thread181-473997 [blue]Worthy Reading![/blue] [thumbsup2]
Also faq181-2886 [blue]Worthy Reading![/blue] [thumbsup2]
 
TheAceMan1,

I have learned that your second suggestion (the one with code starting with [subFormName]) works fine, if I try it in a straightforward Access database. However, the database that I am working on was written by someone else, and I am just trying to make a few modifications to it. The database that I am trying to modify is very complex, with a ton of VBA code associated with each form. Somehow, your suggested approach does not seem to work on it. I don't understand why I am having such problems, except that there are many lines of code associated with the main form, that I have added my subform to.

I did try your most recent suggestion, and also had no luck.

Thanks anyway for your attempt.

Ron
 
Hi TheAceMan1,

You might be interested to learn that with the help of some of your suggested code I have managed to put a "New Record" button into my ornery subform that does get the user to a New Record entry point.

More than one way to skin a cat!

Thanks for the help.

Ron
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top