Solved

VBA Right function

Posted on 2007-11-28
2
4,233 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

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

705 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

19 Experts available now in Live!

Get 1:1 Help Now