Solved

code to set focus on open to placeholder record on datasheet subform

Posted on 2008-11-03
11
297 Views
Last Modified: 2013-11-28
Hello! I have a subform that opens in datasheet view. I'm looking for a way to set the focus on open to the placeholder record so that users don't accidentally overwrite previous data.  I'm assuming this would be a pretty simple code but I don't know what you "call" the blank "placeholder" record :) thanks!!
0
Comment
Question by:jpomerantz
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 5
11 Comments
 
LVL 75
ID: 22868830
Private Sub Form_Load()
Docmd.RunCommand acCmdRecordsGoToNew
End Sub

mx
0
 

Author Comment

by:jpomerantz
ID: 22869665
cool! ok, that works perfectly to set it when the form orriginally loads - but this datasheet is a subform linked to parent form by ID number... is there a way to keep the focus on the new record as the user scrolls (on the parent form) to different records? I tried on got focus, on activate, and a few others and can't figure out which event it would be! I'm assuming this is just a matter of putting your code into the correct event right?
0
 
LVL 75
ID: 22869682
Sure ... sorry ... put this in the On Current of the Main form:

Private Sub Form_Current()
Me.YourSubFormControlName.SetFocus.
Me.YourSubFormControlName.Form.SetFocus.
Docmd.RunCommand acCmdRecordsGoToNew

End Sub
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.

 
LVL 75
ID: 22869721
Sorry .. ignore the last post.

mx
0
 
LVL 75
ID: 22869732
Here you go:

put this in the On Current of the Main form:

Private Sub Form_Current()
Me.YourSubFormControlName.SetFocus
Docmd.RunCommand acCmdRecordsGoToNew

End Sub

I just tested this.

mx
0
 

Author Comment

by:jpomerantz
ID: 22871355
cool! - it works great for me as well - there is just one bug I think... when I get to the end of the records (scrolling with command buttons) or, when I try to navigate to a record using the lookup combo box - it gives me the following error:
Runtime Error 2046:
the command or action 'RecordsGoToView' isn't available now

is there something we can add to fix that?
I really really appreciate your help!!
0
 
LVL 75

Accepted Solution

by:
DatabaseMX (Joe Anderson - Microsoft MVP, Access and Data Platform) earned 500 total points
ID: 22871384
Yes:

Private Sub Form_Current()
If Me.NewRecord = False Then
    Me.YourSubFormControlName.SetFocus
    Docmd.RunCommand acCmdRecordsGoToNew
End If
End Sub

OR

Private Sub Form_Current()
Me.YourSubFormControlName.SetFocus
On Error Resume Next
Docmd.RunCommand acCmdRecordsGoToNew
Err.Clear
0
 

Author Comment

by:jpomerantz
ID: 22871819
second method was the one that worked.  I can't thank you enough!!!

mx, I hope that this is not a violation of EE protocol, but can I ask you to help me with
http://www.experts-exchange.com/Microsoft/Development/MS_Access/Q_23849951.html

I'm not having much luck with that one and I think it's right up your alley :)  
0
 

Author Closing Comment

by:jpomerantz
ID: 31512753
worked perfectly -- thanks so so so much for your time!!!
0
 
LVL 75
ID: 22871851
You are welcome ...

mx
0
 

Author Comment

by:jpomerantz
ID: 22876597
uh oh - slight side effect... I'm going to open a new question for ya - but I wanted to give you a heads up here. thanks so much mx
0

Featured Post

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

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

It’s been over a month into 2017, and there is already a sophisticated Gmail phishing email making it rounds. New techniques and tactics, have given hackers a way to authentically impersonate your contacts.How it Works The attack works by targeti…
Access custom database properties are useful for storing miscellaneous bits of information in a format that persists through database closing and reopening.  This article shows how to create and use them.
With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

726 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