Solved

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

Posted on 2008-11-03
11
295 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
Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

 
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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Describes a method of obtaining an object variable to an already running instance of Microsoft Access so that it can be controlled via automation.
In earlier versions of Windows (XP and before), you could drag a database to the taskbar, where it would appear as a taskbar icon to open that database.  This article shows how to recreate this functionality in Windows 7 through 10.
Basics of query design. Shows you how to construct a simple query by adding tables, perform joins, defining output columns, perform sorting, and apply criteria.
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…

679 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