Solved

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

Posted on 2008-11-03
11
291 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
What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 

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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

QuickBooks® has a great invoice interface that we were happy with for a while but that changed in 2001 through no fault of Intuit®. Our industry's unit names are dictated by RUS: the Rural Utilities Services division of USDA. Contracts contain un…
Experts-Exchange is a great place to come for help with solutions for your database issues, and many problems are resolved within minutes of being posted.  Others take a little more time and effort and often providing a sample database is very helpf…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
In Microsoft Access, learn how to use Dlookup and other domain aggregate functions and one method of specifying a string value within a string. Specify the first argument, which is the expression to be returned: Specify the second argument, which …

758 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

23 Experts available now in Live!

Get 1:1 Help Now