Selasa, 16 Juni 2015

[MS_AccessPros] Re: Combo Box Finds First record instead

 

Ah, Found the problem.  I changed a line in the afterupdate event from

RS.FindFirst "PrimaryKey = " & cboRecordID & ""
to

RS.FindFirst "PrimaryKey = " & strComboVar & ""


Doyce



---In MS_Access_Professionals@yahoogroups.com, <winberry.doyce@...> wrote :

Hello Friends,
I have a weird problem this morning. I've created a form bound to a table with a combo box to look up records like I've done many times. The form opens filtered with "1=2" so it won't display a record. When I enter a number in the combo box for a record, it always goes to record 1 in the table no matter what I type in the combo box however, it only does this when I first open the form. After it displays record 1, then I can type another number in the combo box and it finds the correct record. Here is the code behind the form:
Form_Load():
'fill in start date

    Me.Start_Date = DateSerial(Year(Date), Month(Date), 1)

    'Fill in End date
    Me.End_Date = DateSerial(Year(Date), Month(Date) + 1, 0)

    'hide save button
    If Me.btnSave.Visible = True Then
        Me.btnSave.Visible = False
    End If

    'make form display without record showing
    Me.Filter = "1=2"
    Me.FilterOn = True
    Me.cboRecordID.SetFocus
    

Form_Current():

  Me.cboRecordID = Me.PrimaryKey


Combo Box AfterUpdate

    'Find record on form
    Dim RS As DAO.Recordset
    Dim strComboVar As String
    strComboVar = Me.cboRecordID
   
   
    If Len(cboRecordID & vbNullString) <> 0 Then
        Me.Filter = ""
        Me.FilterOn = True
        Set RS = Me.Recordset.Clone
        RS.FindFirst "PrimaryKey = " & cboRecordID & ""
        If Not RS.NoMatch Then Me.Bookmark = RS.Bookmark
        Set RS = Nothing

    End If


Does anyone have any ideas why this is happening?

Doyce

 

__._,_.___

Posted by: winberry.doyce@roadsysinc.com
Reply via web post Reply to sender Reply to group Start a New Topic Messages in this topic (2)

.

__,_._,___

Tidak ada komentar:

Posting Komentar