Solved

VBA Right function

Posted on 2007-11-28
2
4,235 Views
Last Modified: 2013-12-25
hi experts

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
0
Comment
Question by:zafridi
2 Comments
 
LVL 4

Accepted Solution

by:
origfla earned 125 total points
ID: 20371835
Your code seems right to me, so my guess is that the "strSearchVin" variable might not be the exact same as the "Right(strVinNum, 5)".

So, try this line in your if statement instead:
 If Right(strSearchVin,5) = Right(strVinNum, 5) Then

That way you're comparing apples with apples - that should do it.

Hope this helps
0
 

Author Comment

by:zafridi
ID: 20373888
well when i try what u suggested...it still doesn't work if i just put in 5 numbers in the search text box..but it does work if i enter the whole vin number and gives the result for that...its so weird i don't know why it wouldnt work though...
0

Featured Post

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

816 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now