SetFocus problem

jom1918

Registered User.
Local time
Tomorrow, 05:54
Joined
Apr 26, 2011
Messages
30
I have something wrong in my code. I want the cursor to be positioned at the control "SupplierBatch" after the message box alerts the user that they need to enter the supplier batch details. The code works as I expeceted except that the cursor go to the next control on the form istead of staying at the SupplierBatch control (textbox) What am I doing wrong?

Private Sub SupplierBatch_Exit(Cancel As Integer)
Dim strNewBatch As String
If Nz([SupplierBatch]) = "" Then
Beep
MsgBox "Supplier Batch Details MUST be entered to record this quarantine item. Please enter the Supplier Batch Details Now"
Exit Sub
Me.SupplierBatch.SetFocus

Else
strNewBatch = Me.SupplierBatch.Value
Me.SupplierBatchNumber = strNewBatch
End If
Me.QReg = Me.QID
End Sub
 
Check if this works:

Code:
Private Sub SupplierBatch_Exit(Cancel As Integer)
Dim strNewBatch As String
If Nz([SupplierBatch]) = "" Then
Beep
MsgBox "Supplier Batch Details MUST be entered to record this quarantine item. Please enter the Supplier Batch Details Now"
Me.SupplierBatch.SetFocus
Exit Sub

So you set the focus before you exit the sub.

Catalina
 
Hi Catalina,

It doesn't work. I found another suggestion that added Cancel = True before Set.Focus and that gives the control the focus, but I cannot enter data into the field for some reason.

Private Sub SupplierBatch_Exit(Cancel As Integer)
Dim strNewBatch As String
If Nz([SupplierBatch]) = "" Then
Beep
MsgBox "Supplier Batch Details MUST be entered to record this quarantine item. Please enter the Supplier Batch Details Now"
Cancel = True
Me.SupplierBatch.SetFocus
Exit Sub
Me.SupplierBatch.Locked = False
Else
strNewBatch = Me.SupplierBatch.Value
Me.SupplierBatchNumber = strNewBatch
End If
Me.QReg = Me.QID
End Sub
 
I figured out if I set the focus to another control and then back to the control I want to have the focus, then that works, but I cannot enetr data in the text box. It appears to be locked or not enabled for some reason.

Private Sub SupplierBatch_Exit(Cancel As Integer)
Dim strNewBatch As String
If Nz([SupplierBatch]) = "" Then
Beep
MsgBox "Supplier Batch Details MUST be entered to record this quarantine item. Please enter the Supplier Batch Details Now"
Me.DPBatchNumber.SetFocus
Me.SupplierBatch.SetFocus
Exit Sub
Else
strNewBatch = Me.SupplierBatch.Value
Me.SupplierBatchNumber = strNewBatch
End If
Me.QReg = Me.QID
End Sub
 

Users who are viewing this thread

Back
Top Bottom