?
Solved

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

Posted on 2008-11-03
11
Medium Priority
?
300 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
Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

 
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 2000 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

Simplifying Server Workload Migrations

This use case outlines the migration challenges that organizations face and how the Acronis AnyData Engine supports physical-to-physical (P2P), physical-to-virtual (P2V), virtual to physical (V2P), and cross-virtual (V2V) migration scenarios to address these challenges.

Question has a verified solution.

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

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.
Microsoft Access is a place to store data within tables and represent this stored data using multiple database objects such as in form of macros, forms, reports, etc. After a MS Access database is created there is need to improve the performance and…
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 specify relationships between tables and set various options on the relationship. Add the tables: Create the relationship: Decide if you’re going to set referential integrity: Decide if you want cascade upda…
Suggested Courses

741 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