set focus to first field (1 Viewer)

Siegfried

Registered User.
Local time
Today, 15:56
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: 78
  • InfoNotes.PNG
    InfoNotes.PNG
    3.4 KB · Views: 69
  • taborder.PNG
    taborder.PNG
    18.5 KB · Views: 60
Last edited by a moderator:

theDBguy

I’m here to help
Staff member
Local time
Today, 06:56
Joined
Oct 29, 2018
Messages
21,447
Hi. Are you able to post a sample db?
 

Siegfried

Registered User.
Local time
Today, 15:56
Joined
Sep 11, 2014
Messages
105
Hi,
Thanks for your response and help.
I'll upload a sample later toady.

Best regard,
 

Siegfried

Registered User.
Local time
Today, 15:56
Joined
Sep 11, 2014
Messages
105
attached the database
 

Attachments

  • focus.zip
    236.9 KB · Views: 79

June7

AWF VIP
Local time
Today, 05:56
Joined
Mar 9, 2014
Messages
5,463
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:

Siegfried

Registered User.
Local time
Today, 15:56
Joined
Sep 11, 2014
Messages
105
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: 62
Last edited:

Micron

AWF VIP
Local time
Today, 09:56
Joined
Oct 20, 2018
Messages
3,478
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:

June7

AWF VIP
Local time
Today, 05:56
Joined
Mar 9, 2014
Messages
5,463
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
 

Pat Hartman

Super Moderator
Staff member
Local time
Today, 09:56
Joined
Feb 19, 2002
Messages
43,198
Let me clarify:

1. setting focus to Me.InfoNotes in the InfoNotes_Change() event makes no sense since that event only runs when Me.InfoNotes has the focus so you are trying to set focus to a control that already has the focus.
2. The .text property of a control is only available when the control has the focus. Therefore, you cannot reference the .text property of any control in the current event of the form.
3. Make sure that the unbound control where you are displaying the character count is set to enabled = false and TabStop = No
 

Users who are viewing this thread

Top Bottom