Forum Discussion
Set the Focus
I see that nobody has responded, possibly because, like me, other forum members aren't quite clear what you are asking.
1. Please clarify what type of form you are using: single/continuous/datasheet/split
2. When you refer to the first line of your forms, do you mean the first record or the first control?
3. Why do you need to set the focus to DateOfPurchase using code?
Have you tried altering the tab order so that control is the first item in the tab order?
- faxyladyJul 15, 2021Copper ContributorThanks for your response. Maybe we can get together next week to help solve a few other problems.
I have copied and pasted this code into what I believe is a module. When I click compile, the statement appears in red with the error message, "Expected: End of Statement" The If is highlighted in blue. - faxyladyJul 08, 2021Copper ContributorDateofPurchase is the first control of the form. I want the cursor to appear here when a new record is started. Thank you.
- michaelmerlinJul 09, 2021Copper ContributorInstead of writing code, another option might be just setting properties of various controls, most importantly the tab order which is
Tab Index
also combined with these 2 additional properties:
Tab Stop
Enabled- faxyladyJul 09, 2021Copper ContributorThank you for responding.
I don't believe this would work as the form is created from the table.
Remember what I am trying g to do is have the cursor blink on the first control for each new record.
- faxyladyJul 08, 2021Copper Contributor
Thank you for responding so quickly.
Single form.
What I am trying to do is get the cursor to appear on the first control of the record when the end user is finished entering data on the previous record. What the cursor is doing at present is remaining on the last control entered by the end user when a new record is begun, although on the new record.
I was given this code many years ago and it always worked. But now it is not. I am trying to figure out what is wrong. I do not write code yet. Will be learning soon.
Private Sub Form_Current()
If Me.NewRecord = True Then
Me.DateofPurchase.SetFocus
End If
End Sub
- isladogsJul 07, 2021MVP
Forgot to say...
The NewRecord property is for the form...not a specific control.
Something like this should work
Sub NewRecordMark(frm As Form) If frm.NewRecord = True Then MsgBox "You're in a new record." End Sub- faxyladyJul 08, 2021Copper ContributorYour code did not work when I hit the Next Record Button or the Add New Record Button. The cursor should appear on the very first line, "DateofPurchase."