Wrox Programmer Forums
|
VB Databases Basics Beginning-level VB coding questions specific to using VB with databases. Issues not specific to database use will be redirected to other forums.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the VB Databases Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old March 6th, 2006, 01:45 PM
Authorized User
 
Join Date: Dec 2005
Posts: 32
Thanks: 0
Thanked 0 Times in 0 Posts
Default FindFirst retrieves wrong record

Hi there,

I have the following code to sync the 'Detailed User Report ALL' form with the selected Username in the combo box in the 'main menu' form, which you then click to sync.


'=======================================
Private Sub cmdSearch_Click()

If IsNull(Me.cmbUserSelect) Then
        MsgBox "Please select a UserName to search."
        Exit Sub
End If

Dim formname, SyncCriteria As String
Dim f As Form, rs As Recordset

formname = "Detailed User Report ALL form"

If Not SysCmd(acSysCmdGetObjectState, acForm, formname) Then
        DoCmd.OpenForm formname
End If

Set f = Forms(formname)
Set rs = f.RecordsetClone

SyncCriteria = BuildCriteria("UserName", dbText, _
Me.cmbUserSelect)

rs.FindFirst SyncCriteria

'MsgBox rs.Fields("UserName") 'to check the Username of the combo box in mainmenu

If rs.NoMatch Then
        MsgBox "No match exists!", 64, formname
Else
        f.Bookmark = rs.Bookmark
End If

'MsgBox f![UserName] 'check the current Username of the form thats meant to be synchronized.

Me.Visible = False

Set f = Nothing
Set rs = Nothing

End Sub

'=======================================

There are the exact same number of records in the cmbUserSelect combo box as there are in the 'Detailed User Report ALL' form since they refer to the same source. but for some reason the procedure only works for some UserName values and not others. I cant figure out why because I have used this procedure in other parts of my project and works fine. only they are based on the current record in a Datasheet, where as this is based on a combo-box selection. Any help and advice is much appreciated, thank you for your time.

Derek

 
Old March 6th, 2006, 01:50 PM
Authorized User
 
Join Date: Dec 2005
Posts: 32
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Sorry, when I said that it only works for some UserName values, i was referring to the synchronization. The procedure retrieves the wrong record for some and works fine for others. I have tested this thoroughly and does not occur randomly. thanks.






Similar Threads
Thread Thread Starter Forum Replies Last Post
What is wrong with this code to add a record? Patc4 Pro VB.NET 2002/2003 0 March 25th, 2008 07:18 AM
Using FindFirst in Dropdown Field rmurray VB How-To 0 July 26th, 2007 09:54 AM
Combo Box posting to Wrong Record alaxmen Access 1 February 3rd, 2006 12:56 PM
findfirst function and vc++ amira C# 0 September 29th, 2005 07:42 AM
findfirst help Raif Access 1 June 14th, 2004 03:31 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.