v lookup problem

  • Thread starter Thread starter ghost
  • Start date Start date
G

ghost

Greeting,
I have an excel sheet for inputting employees data. In this sheet there is a
command to open a form to input data and there is a textbox which is employee
id. What I want to do is to check the employee id if it is already excess, a
msgbox shows and tell the user that it is already excess any should be
change. There is a problem with my code but I don't where it is.
Can any body help me please?

Private Sub TextBox3_Change()
If Not IsNull(vLookup("[ID]", "[Data]", "[ID] = " & [TextBox3])) Then

MsgBox "Sorry… the ID is already input please reenter the Id " _
, vbOKOnly + vbCritical, _
"Duplicated ID"

DoCmd.CancelEvent

End If
 
Are you sure you didn't want to post this question in an Access forum?

That DoCmd doesn't look like excel...

But if you really meant excel...

Option Explicit
Private Sub TextBox3_Change()

dim Res as variant
dim RngToCheck as range

with worksheets("somesheetnamehere")
set rngtocheck = .range("a1",.cells(.rows.count,"A").end(xlup))
end with

res = application.match(textbox3.value, rngtocheck, 0)

if iserror(res) then
'not found
else
'it matched
end if

End Sub

And are you really sure you want this to run with each change to the textbox?


Greeting,
I have an excel sheet for inputting employees data. In this sheet there is a
command to open a form to input data and there is a textbox which is employee
id. What I want to do is to check the employee id if it is already excess, a
msgbox shows and tell the user that it is already excess any should be
change. There is a problem with my code but I don't where it is.
Can any body help me please?

Private Sub TextBox3_Change()
If Not IsNull(vLookup("[ID]", "[Data]", "[ID] = " & [TextBox3])) Then

MsgBox "Sorry… the ID is already input please reenter the Id " _
, vbOKOnly + vbCritical, _
"Duplicated ID"

DoCmd.CancelEvent

End If
 

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

Back
Top