Solved Navigating through a form using combo box selection? (1 Viewer)

Sampoline

Member
Local time
Tomorrow, 08:50
Joined
Oct 19, 2020
Messages
161
I want to navigate to records on my form, via combo box selection.

In the afterupdate event of my combo box, I have the code:

Code:
Dim rs As DAO.Recordset
    If Not IsNull(Me.cboMoveTo) Then
        'Save before move.
        If Me.Dirty Then
            Me.Dirty = False
        End If
        'Search in the clone set.
        Set rs = Me.RecordsetClone
        rs.FindFirst "[ID_Index] = """ & Me.cboMoveTo & """"
        If rs.NoMatch Then
            MsgBox "Not found: filtered?"
        Else
            'Display the found record in the form.
            Me.Bookmark = rs.Bookmark
        End If
        Set rs = Nothing
    End If
End Sub

ID_Index represents the PK of the form's table.

Code works initially. I'm able to navigate to different records. But once I close the database or form, the navigation stops working; rs.NoMatch keeps triggering.

Idk if it helps:
But I have in the form properties, Data Entry = Yes.
Form_Dirty has my save button enabled (Me.cmdSave.Enabled = True). Only when user modifies record does the save button enable, otherwise it stays disabled.
On Form_Open, all fields are disabled and enabled NewRecord_OnClick (when a new record is created).

There's still a few things that maybe worth mentioning, but not sure if any of it is relevant.
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Tomorrow, 06:50
Joined
May 7, 2009
Messages
19,229
data entry=Yes, is for "data entry", your form will "always" go to "New Record".
advised to google the use of this property for your illuminance.

to disable addition of new record when "Data Entry=No", you add code to
BeforeInsert() event of the form, setting Cancel = True.
 

Sampoline

Member
Local time
Tomorrow, 08:50
Joined
Oct 19, 2020
Messages
161
data entry=Yes, is for "data entry", your form will "always" go to "New Record".
advised to google the use of this property for your illuminance.

to disable addition of new record when "Data Entry=No", you add code to
BeforeInsert() event of the form, setting Cancel = True.
Well I wanted the form to display a blank record whenever it is opened, that's why I set Data Entry = Yes. Not sure if this in anyway affects my above problem though.

Also if I wanted to disable additions, I could just set the Form's properties for Allow Additions to "No", right?
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Tomorrow, 06:50
Joined
May 7, 2009
Messages
19,229
you can always Goto New record on your Form's Load event:

docmd.GoToRecord ,,acNewRec
 

Sampoline

Member
Local time
Tomorrow, 08:50
Joined
Oct 19, 2020
Messages
161
you can always Goto New record on your Form's Load event:

docmd.GoToRecord ,,acNewRec
Ok but my issue now is the navigation of records. I just want to know why my form isn't opening the record selected from the combo box. My code in the OP works, but only after I've made a new record and before I've closed the form/database. Once I close it, the form does not navigate to that record anymore.
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Tomorrow, 06:50
Joined
May 7, 2009
Messages
19,229
what is the DatatType of [ID_Index]?
if Numeric:

rs.FindFirst "[ID_Index] = " & Me.cboMoveTo
 

Sampoline

Member
Local time
Tomorrow, 08:50
Joined
Oct 19, 2020
Messages
161
what is the DatatType of [ID_Index]?
if Numeric:

rs.FindFirst "[ID_Index] = " & Me.cboMoveTo
Ok so datatype is supposed to be a number. I actually had it set as:

Code:
rs.FindFirst "[ID_Index] = " & Me.cboMoveTo

But I've just been experimenting to fix my issue and changed the PK to a text type and so used:

Code:
rs.FindFirst "[ID_Index] = """ & Me.cboMoveTo & """"

But neither is working..
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Tomorrow, 06:50
Joined
May 7, 2009
Messages
19,229
There's still a few things that maybe worth mentioning, but not sure if any of it is relevant
what are those?

what is your Recordsource?
 

Sampoline

Member
Local time
Tomorrow, 08:50
Joined
Oct 19, 2020
Messages
161
what are those?

what is your Recordsource?
Well the database has already been created, so there are quite a few form events for example. I was wondering if any of them can interfere record navigation.
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Tomorrow, 06:50
Joined
May 7, 2009
Messages
19,229
current event will when you from record to record.
 

Sampoline

Member
Local time
Tomorrow, 08:50
Joined
Oct 19, 2020
Messages
161
current event will when you from record to record.
When I change the form property back from data entry = yes to no, everything works again.. i guess I'll have to leave data entry = no

In saying that, are there any other alternative method to display a blank record when form_open?
 

Sampoline

Member
Local time
Tomorrow, 08:50
Joined
Oct 19, 2020
Messages
161
you can always Goto New record on your Form's Load event:

docmd.GoToRecord ,,acNewRec
Just realised you've actually answered that here already. Everything works fine now. Thankyou Arnel.
 

Users who are viewing this thread

Top Bottom