Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

VBA Right function

Status
Not open for further replies.

teachmecr

Programmer
Oct 1, 2006
72
US
Hi

can plz someone tell me why the following code doesn't give me the expected results. if i do the exact search for strSearchVin = strVinNum...it gives me the correct results but somehow doesn't work with RIGHT function. I wana look up my results from the text box (by exact number or last 5 matching numbers). Thanks

Private Sub cmdSearch_Click()
Dim strVinNum As String
Dim strSearchVin As String

'Check for Null value

If IsNull(Me![txtVinSearch]) Or (Me![txtVinSearch]) = "" Then
MsgBox "Please enter a value!", vbOKOnly, "Invalid Search"
Me![txtVinSearch].SetFocus
Exit Sub
End If



DoCmd.ShowAllRecords
DoCmd.GoToControl ("EquipSerialNum")
DoCmd.FindRecord Me!txtVinSearch

EquipSerialNum.SetFocus
strVinNum = EquipSerialNum.Text
txtVinSearch.SetFocus
strSearchVin = txtVinSearch.Text


If strSearchVin = Right(strVinNum, 5) Then
EquipSerialNum.SetFocus
txtVinSearch = ""

Else
MsgBox "Match Not Found", _
txtVinSearch.SetFocus
End If
End Sub
 
What is the value of strSearchVin and strVinNum?

ck1999
 
strsearchvin takes the value from a textbox that the user is going to enter which gets compared with actual vinnum(strvinnum) and strvinnum holds the actual values from one of the textboxes of the form...they are coming from a view thur odbc (sql)..
 




When you say that it does not give the expected results...

what was in the textbox in the instance that did not work, what did you expect, and what actually happened?

Help us out here.

Skip,
[sub]
[glasses] When a diminutive clarvoyant had disappeared from detention, headlines read...
Small Medium at Large[tongue][/sub]
 
what i'm trying to say is this: i have a textbox "txtVinSearch". when i type in a full vin number in it it takes me to the particular record for that vin in the form...but i wana be able to just search on the last 5 numbers of the vin..and when i type in the last 5 numbers of the vin..it doesn't take me to that particular record on the form..Above is my code where im only searching by the last 5 numbers...Basically im trying to give users a search ability..i hope this explains my scenario..thanks
 
I think the problem is when you use the right function you are not calling DoCmd.findrecord.

You may want to do like you have DoCmd.FindRecord Me!txtVinSearch and if no search found try using something similar to docmd.findrecord "*" & right(Me!txtVinSearch,5)

I did not try this but using the * in your find may help.

ck1999
 
thanks a lot man...it worked..i really appreciate ur help..i have to try both search criterias at the same time ...so lets see...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top