PDA

View Full Version : VBA Right function



zafridi
11-29-2007, 02:05 PM
hi all

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

asingh
11-30-2007, 03:18 AM
Hi,
try

If strSearchVin = val(Right(strVinNum, 5)) Then
....
....

end if