Set Cursor Position in first field of new record on form

Solola

Board Regular
Joined
Sep 23, 2003
Messages
73
I'm trying to make the default cursor location the first field of a new form. I have the form's property Data Entry set to Yes, but that didn't do it.

So, I tried the following code on the On Load property of the form, but when I try to load a new record, I get a Compile error: Method or data member not found (and it highlights SetFocus as the error):

Private Sub Form_Load()
Me.nmdp_rid.SetFocus
End Sub

I also tried an if statement to determine if it's a new record before setting the focus, but that doesn't work, either (same error message).

What am I doing wrong?
 

Excel Facts

Fastest way to copy a worksheet?
Hold down the Ctrl key while dragging tab for Sheet1 to the right. Excel will make a copy of the worksheet.
If you make sure the control is a tab stop and has the lowest tab index it should be the control that gets the focus. These are on the "other" tab for control properties, I think. Your error is odd, though. Could be a more serious problem. The control should exist and have a set focus method.

ξ
 
Upvote 0
Well, it is the first tab stop in my form's Detail section.

But, I have a couple fields in the Header that are autonumber and autodate. I checked, and the Tab Stop properties were set to Yes for both of these. Changing them to No solved my problem. Thanks for the fix!!
 
Upvote 0
Well, it kind of worked. Now the cursor is in the first field when I open the form for the first time. But, when I complete entry of one record and go to a new record, the cursor does not appear to be anywhere. I have to click in the first field in order to start data-entering.
 
Upvote 0
I should point out - I moved to a new record via a command button I created...if I just tab to a new record instead, the cursor is in the correct field. So, this will be my fix. I'll just educate my users to tab to a new record.
 
Upvote 0
But, when I complete entry of one record and go to a new record,

Not sure. How are you saving the record? Is the form showing a single record at a time and only for data entry?
 
Upvote 0
Yes, it's a data entry form, but if the user tabs (or uses my now extinct command button) to enter a new record, the user can navigate thru all records that were entered in that session. As soon as they close, and enter the form again, only a blank form is visible.

(I guess I'm not sure what prompts the save - completion of all required fields and a tab to the next record?)
 
Upvote 0
I guess you could use the on current event to place the cursor on the control you want to start in.

That was your original problem, though. Try again? Or don't worry about it? Does the user really care where the cursor is? If it's in the first control for new entry that's probably all you need. It doesn't have to be anywhere particular for just scrolling through records.
 
Upvote 0
Does the user really care where the cursor is? If it's in the first control for new entry that's probably all you need. It doesn't have to be anywhere particular for just scrolling through records.

Agreed. The cursor is in the right field when the form is first opened and when a new record is tabbed to. That should be okay (although I'm still curious why the SetFocus didn't work...).
 
Upvote 0
Dunno. Sometimes I just erase the code and re-enter and then recompile it. It *should* work really ... You might try the activate event instead of the load event. Or the current event (which should work for new and existing records). I just tested a setfocus on a textbox when a form loads and no problems. We'll probably just have to consider this "one of life's mysteries".
 
Upvote 0

Forum statistics

Threads
1,224,599
Messages
6,179,828
Members
452,946
Latest member
JoseDavid

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top