Solved

VBA Right function

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

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…
If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
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…

911 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

26 Experts available now in Live!

Get 1:1 Help Now