Solved

MS Access Recordset Search

Posted on 2009-07-09
5
676 Views
Last Modified: 2013-11-28
I'm attempting to search a recordset for an integer using the attached code. Included in the code snippet is an if...then...else construct that is puzzling me. I can't get the else part to come true. This results in the user always being taken to pallet 1 (first item in recordset) if the record isn't found which is deceiving. Any help would be much appreciated.

Please let me know what else you might need from me.

Thanks
Private Sub cmbPalletSearch_AfterUpdate()

    On Error Resume Next

    

    Me.FilterOn = False

    

    Dim rs As Recordset

    Set rs = Me.Recordset.Clone

    

    rs.FindFirst "[PalletNumber] = " & Me![cmbPalletSearch]
 

    If Not rs.EOF Then

        Me.Bookmark = rs.Bookmark

    Else

        rs.FindFirst "PalletNumber = " & iLocate

        MsgBox "Pallet Not Found"

    End If

End Sub

Open in new window

0
Comment
Question by:ghjeffeii
  • 3
  • 2
5 Comments
 
LVL 77

Expert Comment

by:peter57r
ID: 24820798
rs.FindFirst "[PalletNumber] = " & Me![cmbPalletSearch]
' tries to find the pallet number matching the value in the form

    If Not rs.EOF Then
' assumes that if you don't reach eof then something is found
        Me.Bookmark = rs.Bookmark
' sets the form record pointer to the found record

    Else
' there is no match

        rs.FindFirst "PalletNumber = " & iLocate
' find the pallet corresponding to iLocate
' there is no clue in the code as to what iLocate is - the value must be set elsewhere
' but nothing happens to the found record in this code

        MsgBox "Pallet Not Found"
    End If
0
 

Author Comment

by:ghjeffeii
ID: 24824744
Sorry, iLocate is declared as Long in the general declarations section of the form and initialized w/ the below code snippet. My thinking was that if the record isn't found in the record then the form would return to the record (pallet) that the form was on before the user performed the search. I know through debugs that the BeforeUpdate event returns the current record properly and the AfterUpdate event also returns the correct record, but alas i always end up on record 1 if the pallet being searched isn't found.

Private Sub cmbPalletSearch_BeforeUpdate(Cancel As Integer)
    iLocate = Nz(Me.txtPalletNumber, 0)
End Sub
0
 

Author Comment

by:ghjeffeii
ID: 24831869
Any comments, suggestions, solutions...?
0
 
LVL 77

Expert Comment

by:peter57r
ID: 24834322
I suppose the obvious Q is why you are not basing the rowsource of the combo box on the pallet numbers that do exist and restricting the user's choice to the list.

0
 

Accepted Solution

by:
ghjeffeii earned 0 total points
ID: 24835020
I ended up just using the NotInList event instead, but I don't understand why the original If...Then...Else construct didn't work correctly here.
0

Featured Post

Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

Question has a verified solution.

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

In the previous article, Using a Critera Form to Filter Records (http://www.experts-exchange.com/A_6069.html), the form was basically a data container storing user input, which queries and other database objects could read. The form had to remain op…
The first two articles in this short series — Using a Criteria Form to Filter Records (http://www.experts-exchange.com/A_6069.html) and Building a Custom Filter (http://www.experts-exchange.com/A_6070.html) — discuss in some detail how a form can be…
In Microsoft Access, learn the trick to repeating sub-report headings at the top of each page. The problem with sub-reports and headings: Add a dummy group to the sub report using the expression =1: Set the “Repeat Section” property of the dummy…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

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

19 Experts available now in Live!

Get 1:1 Help Now