Solved

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

Posted on 2008-11-03
11
292 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
  • 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
 
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
U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

 

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 - Access MVP) 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

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.

Question has a verified solution.

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

Suggested Solutions

Most if not all databases provide tools to filter data; even simple mail-merge programs might offer basic filtering capabilities. This is so important that, although Access has many built-in features to help the user in this task, developers often n…
In the previous article, Using a Critera Form to Filter Records (http://www.experts-exchange.com/A_6069.html), the form was basically a data container storing user input, which queries and other database objects could read. The form had to remain op…
Familiarize people with the process of utilizing SQL Server views from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Access…
Familiarize people with the process of utilizing SQL Server stored procedures from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Micr…

910 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now