Control the cursors location via code.

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I'm creating an application that controls visitor's badges to our facility.
I want to ensure that one badge can not be issued to more than one
individual at a time. I've borrowed the following code but I'd like the
cursor to remain in the BadgeNumber text box if the message box is triggered.
Eventually, I will add a button to the message box that will allow me to go
to the record called out in the message box - that's why I'd like to know
where the duplication is occuring.
Again, if a duplicate is found - I'd like the cursor to remain in
BadgeNumber text box.

Private Sub BadgeNumber_AfterUpdate()

Dim StrWhere As String
Dim varResult As Variant

With Me.BadgeNumber
If (.Value = .OldValue) Then
'do nothing
Else
StrWhere = "BadgeNumber = """ & .Value & """"
varResult = DLookup("ID", "tblAccessControl", StrWhere)
If Not IsNull(varResult) Then
MsgBox "That Badge has Already been Issued in Record " &
varResult, 16
End If
End If
End With
End Sub
 
You need to issue Me!BadgeNumber.SetCursor after the MsgBox and before the
first End If ---
 
First off, thank you for your speedy response.
I inserted the code as stated which resulted in a run time error '438':
Object doesn't support this property or method.
I'm using MS Access 2000 if that makes a difference.
Daiuy
 
Sorry --- your question on the "cursor" got my brain twisted --- it's not
"SetCursor" --- it's "SetFocus" !!! Bob.
 
Else
StrWhere = "BadgeNumber = """ & .Value & """"
varResult = DLookup("ID", "tblAccessControl", StrWhere)
If Not IsNull(varResult) Then
MsgBox "That Badge has Already been Issued in Record " &
varResult, 16
Cancel = True
End If
 
Nope, the "Cancel = True" didn't work

Klatuu said:
Else
StrWhere = "BadgeNumber = """ & .Value & """"
varResult = DLookup("ID", "tblAccessControl", StrWhere)
If Not IsNull(varResult) Then
MsgBox "That Badge has Already been Issued in Record " &
varResult, 16
Cancel = True
End If
 
Bob,
Correct me if I am wrong, but I think you cannot use a SetFocus on the
active control.
 
The "Me!BadgeNumber.SetFocus" didn't work either.
My frustration from yesterday is returning
 
The SetFocus didn't work.

I believe if you place all of the code (including that from Klatuu) in the
BeforeUpdate event (which has a Cancel event) rather than the AfterUpdate
event it will work as you desire.

hth

RuralGuy
 
Success!
Thank you all for your input.
Placing the code in the BeforeUpdate vice AfterUpdate seems to have done the
trick.
Thanks again.
 
Daiuy said:
Success!
Thank you all for your input.
Placing the code in the BeforeUpdate vice AfterUpdate seems to have
done the trick.
Thanks again.

You are very welcome from all of us.

RuralGuy
 
Back
Top