Solved

VBA Right function

Posted on 2007-11-28
2
4,236 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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 Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
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…
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…

749 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