Control the cursors location via code.

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
 
B

Bob Howard

You need to issue Me!BadgeNumber.SetCursor after the MsgBox and before the
first End If ---
 
G

Guest

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
 
B

Bob Howard

Sorry --- your question on the "cursor" got my brain twisted --- it's not
"SetCursor" --- it's "SetFocus" !!! Bob.
 
G

Guest

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
 
G

Guest

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
 
G

Guest

Bob,
Correct me if I am wrong, but I think you cannot use a SetFocus on the
active control.
 
G

Guest

The "Me!BadgeNumber.SetFocus" didn't work either.
My frustration from yesterday is returning
 
R

RuralGuy

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
 
G

Guest

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

RuralGuy

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top