set focus to first field

Siegfried

Registered User.
Local time
Today, 07:51
Joined
Sep 11, 2014
Messages
105
Dear Experts,

I have a set focus issue on my form ADUserF when creating a new record!?
The form has a text box InfoNotes, set to field size 255.
I've added an unbound text box textCharsUsed to display the remaining characters available when typing in comment in the InfoNotes field

I have following code on change Event Procedure:
UG Added Code Tags
Code:
Private Sub InfoNotes_Change()
'Used in the On Change event of the form
'to display character count when the record
'is being added/amended
    Me.InfoNotes.SetFocus
    If Not IsNull(Me.InfoNotes.Text) Then
            Me.txtCharsUsed = (255 - (Len(Me.InfoNotes.Text)))
        Else
            Me.InfoNotes = 0
    End If
    
End Sub
 
Private Sub Form_Current()
'Used in the On Current event of the form
'to display character count in InfoNotes in txtCharsUsed when scrolling
'through each record
    Me.InfoNotes.SetFocus
    If Not IsNull(Me.InfoNotes.Text) Then
            Me.txtCharsUsed = (255 - (Len(Me.InfoNotes.Text)))
        Else
            Me.InfoNotes = 0
    End If
'to keep the optiongroup color when closing the form
    Call FramePasswordNeverExpires_AfterUpdate
End Sub

When I want to create a new record the focus goes to field logonname instead of the first field UserStatusI.Tab order is set correctly though.

Thanks for helping me out.

Best regards,

Siegfried
 

Attachments

  • ADUserF.PNG
    ADUserF.PNG
    28.3 KB · Views: 142
  • InfoNotes.PNG
    InfoNotes.PNG
    3.4 KB · Views: 128
  • taborder.PNG
    taborder.PNG
    18.5 KB · Views: 127
Last edited by a moderator:
Hi. Are you able to post a sample db?
 
Hi,
Thanks for your response and help.
I'll upload a sample later toady.

Best regard,
 
For future, please post code between CODE tags to retain indentation and readability.

Color scheme on your form is frustrating, hard to read labels.

Current event sets focus to InfoNotes so the next control is LogonName.

Why have code to enter 0 into InfoNotes field? Which never seems to happen anyway.

Suggest change code for Current event.
Code:
Private Sub Form_Current()
'Used in the On Current event of the form
'to display character count in InfoNotes in txtCharsUsed when scrolling
'through each record
    If Not IsNull(Me.InfoNotes) Then
            Me.txtCharsUsed = (255 - (Len(Me.InfoNotes)))
    End If
'to keep the optiongroup color when closing the form
    Call FramePasswordNeverExpires_AfterUpdate
End Sub
And set ADUserID TabStop to No.
 
Last edited:
I changed my code as suggested but then the count isn't working anymore in [txtCharsUsed] unbound text box?
In my original code, when I try to type into the notes field [InfoNotes] a text box, it jumps to the cboUserStatus eacht time.
The code to enter 0 is from the original code, at first it added up the number of characters typed but I wanted a countdown from 250 hence added (255 -).
 

Attachments

  • FocusIssue.PNG
    FocusIssue.PNG
    38.6 KB · Views: 121
Last edited:
why not just set the calculated field to 255 - Len(someControl? In current event, use control value (default). In ChangeEvent, probably .Text property (assuming it's bound). It makes no sense to me to validate whether or not it is Null in the Change event since the length property value will either be zero or some number greater than zero.

EDIT - actually probably doesn't matter if it's bound or not.
 
Last edited by a moderator:
Try this:
Code:
Private Sub Form_Current()
'Used in the On Current event of the form
'to display character count of InfoNotes in txtCharsUsed when scrolling through each record
    Me.txtCharsUsed = 255 - Len(Nz(Me.InfoNotes, ""))
'to keep the optiongroup color when closing the form
    Call FramePasswordNeverExpires_AfterUpdate
End Sub
 

Users who are viewing this thread

Back
Top Bottom