Rabu, 17 Juni 2015

RE: [MS_AccessPros] Re: Combo Box Finds First record instead

 

Thanks Graham! I'll give this a try.

Doyce

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

Hi Doyce

Yes, this is happening because you first remove the filter, which temporarily displays all records.  As the current record has changed, Form_Current will fire, which actually changes the value of your combo box to the K of the first record.

Another approach, if you don't want to navigate forwards and backwards after choosing a record, might be to simply change the Filter:

Me.Filter = "PrimaryKey = " & cboRecordID

Best wishes,
Graham [Access MVP since 1996]

 

From: MS_Access_Professionals@yahoogroups.com [mailto:MS_Access_Professionals@yahoogroups.com]
Sent: Wednesday, 17 June 2015 00:29
To: MS_Access_Professionals@yahoogroups.com
Subject: [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 (4)

.

__,_._,___

Tidak ada komentar:

Posting Komentar