Cannot set focus to the Control

comfygringo

New member
Local time
Today, 15:07
Joined
Jul 28, 2013
Messages
9
This code stopped working without explanation after the longest time. I can't seem to fix it.

Code:
Private Sub Send_Letter_AfterUpdate()
    Call Set_CallDateUserId
End Sub

Private Sub Set_CallDateUserId()
    Me.txtCallDate.SetFocus
    Me.txtCallDate.enabled = True
    Me.txtCallDate.Locked = False
    If Me.txtCallDate.Text = "" Or Me.txtCallDate.Text Is Null Then
        Me.txtCallDate.Text = Date
    End If
    Me.txtCallDate.enabled = False
    Me.txtCallDate.Locked = True
    
    Me.txtUserID.SetFocus
    Me.txtUserID.enabled = True
    Me.txtUserID.Locked = False
    If Me.txtUserID.Text = "" Or Me.txtUserID.Text Then
        Me.txtUserID.Text = myUserID
    End If
    Me.txtUserID.enabled = False
    Me.txtUserID.Locked = True
    Me.Refresh
End Sub
 
I got it working after searching the threads. Research always pays off!

Thanks, guys!
 
If you care to post the solution other users may benefit from it.

Thanks

Catalina
 
Your code is more complicated than it needs to be, probably because you were using the .text property. In VB forms, the .text property is the default property but in .vba (Access), the default property is .value. The ONLY time you can reference the .text property is if a control has the focus. You can reference the .value property any time. Only use the .text property if you actually need to trap keystrokes as they are being typed. For all other purposes, use the .value property. Since it is the default property, you can eliminate .value when referencing controls.
Code:
Private Sub Set_CallDateUserId()
    If Me.txtCallDate = "" Or Me.txtCallDate Is Null Then
        Me.txtCallDate = Date
    End If
    If Me.txtUserID = "" Or Me.txtUserID Then
        Me.txtUserID = myUserID
    End If
End Sub
 
You are right! This is the solution I came up with. It does pretty much what you suggested.

Code:
Private Sub Set_CallDateUserId()
    If IsNull(Me.txtCallDate) Then
        Me.txtCallDate = Date
    End If

    If IsNull(Me.txtUserID) Then
        Me.txtUserID = myUserID
    End If

    Me.Refresh
End Sub
 

Users who are viewing this thread

Back
Top Bottom