[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

VBA Right function

Posted on 2007-11-28
2
Medium Priority
?
4,241 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 375 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: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying 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

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
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…
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…
Suggested Courses

656 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