Solved Go To The Next Record (1 Viewer)

Eljefegeneo

Still trying to learn
Local time
Yesterday, 16:31
Joined
Jan 10, 2011
Messages
904
If I use the standard VBA to open a specific form, that is:
Code:
DoCmd.OpenForm "frmNewNames", , , "ID = " & Forms!frmLastN.txtLastN
I open the exact record I want.

But when I get to frmNewNames and then want to go to the next record it says I cannot. I've looked up a solution but can't seem to find one that works. I was using the standard gotonext macro, then tried.
Code:
DoCmd.GoToRecord acDataForm, "frmNewNames", acGoTo, 7
And variations of the above to no avail. If I tell it to remove the filters first before going to a new record,
Code:
Me.Filter = ""
Me.FilterOn = False[\code]
It still won't go anywhere.

I then tried the following found on a forum:
[code]Filter = ""
FilterOn = False
Const NO_NEXT_RECORD = 2105
    Me.AllowAdditions = True
    On Error Resume Next
    DoCmd.GoToRecord acDataForm, "frmNewNames", acGoTo, 7
    Select Case Err.Number
        Case 0
       Case NO_NEXT_RECORD
        Case Else
        MsgBox Err.Description, vbExclamation, "Error"
    End Select

But that gets me to the next record only and no further.

I also would like the filter to be removed and have the ability to go to the previous record.
 

theDBguy

I’m here to help
Staff member
Local time
Yesterday, 16:31
Joined
Oct 29, 2018
Messages
21,467
Hi. To remove the filter, you can execute the following code:
Code:
Me.Filter = ""
Me.FilterOn = False
Hope that helps...
 

pbaldy

Wino Moderator
Staff member
Local time
Yesterday, 16:31
Joined
Aug 30, 2003
Messages
36,125
I don't think filter code does anything when a form was opened with a wherecondition. It appears you've already tried what db guy suggested. Perhaps opening it without a filter but still to the desired record?

 

Eljefegeneo

Still trying to learn
Local time
Yesterday, 16:31
Joined
Jan 10, 2011
Messages
904
I did do that, didn't I? First two lines of the code.
 

bastanu

AWF VIP
Local time
Yesterday, 16:31
Joined
Apr 13, 2010
Messages
1,402
Can you try to use the suggestion in post #9 of this thread:


Cheers,
Vlad
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 07:31
Joined
May 7, 2009
Messages
19,230
after disabling the filter, do a Requery, then go to the desired record:
Code:
Me.FilterOn = False
Me.Requery
DoCmd.GoToRecord acActiveDataObject, Me.Name, acGoTo, 7
 

strive4peace

AWF VIP
Local time
Yesterday, 18:31
Joined
Apr 3, 2020
Messages
1,004
hi Eljefegeneo,

when you open the form, is new record available to go to manually?

If not:
  • Is there more than one table in the RecordSource? If so, can you change that to just use the table you want to add a record to?
  • In the form design, what is the property setting for AllowAdditions and AllowEdits? Both must be Yes
Here is another way to go to a new record that makes things more clear if the form you want to add a record to is the active object

DoCmd.RunCommand acCmdRecordsGoToNew
 

Cronk

Registered User.
Local time
Today, 09:31
Joined
Jul 4, 2013
Messages
2,772
The issue is highlighted in #3 by Paul. The form has been opened with a WHERE clause. The form's recordsource contains only one record if ID is the key field.

Options are
1 Open the form with a filter, not a where clause
2 Open the form with no filter/where but with openargs and then in the load event position the record to be displayed
3 Open the form with no filter/where clause, and in the procedure opening the form, position the record to be displayed
4 After displaying the single record, change the form's recordsource and then go to the desired record
5 Something else that I can't think of :)
 

Gasman

Enthusiastic Amateur
Local time
Today, 00:31
Joined
Sep 21, 2011
Messages
14,260
I was curious about this and found that if I used the Where clause I too got one record as I used the ID field.
Then if I just switched the filter off, I did not actually clear the filter (just being lazy) I got back all my records.?

The only drawback was the record being displayed was the first record, but that could easily be overcome.?

I myself would go with the openargs option.?
 
Last edited:

theDBguy

I’m here to help
Staff member
Local time
Yesterday, 16:31
Joined
Oct 29, 2018
Messages
21,467
The issue is highlighted in #3 by Paul. The form has been opened with a WHERE clause. The form's recordsource contains only one record if ID is the key field.

Options are
1 Open the form with a filter, not a where clause
2 Open the form with no filter/where but with openargs and then in the load event position the record to be displayed
3 Open the form with no filter/where clause, and in the procedure opening the form, position the record to be displayed
4 After displaying the single record, change the form's recordsource and then go to the desired record
5 Something else that I can't think of :)
Okay, unless I am misreading the problem, I really don't understand it. I said it earlier, I tried clearing the filter and it worked for me. So, just to make sure I wasn't going crazy, I created a small demo. Please let me know what I am missing. Thanks!
 

Attachments

  • FilterDemo.zip
    32.6 KB · Views: 119
Last edited:

pbaldy

Wino Moderator
Staff member
Local time
Yesterday, 16:31
Joined
Aug 30, 2003
Messages
36,125
I did notice that the "Filtered" icon on the bottom of a form opened with a wherecondition could be clicked on to get the full recordset displayed. Presumably a specific set of steps needs to be taken in code to recreate that, as I'm sure db guy and others are using.
 

Eljefegeneo

Still trying to learn
Local time
Yesterday, 16:31
Joined
Jan 10, 2011
Messages
904
Been busy and I do appreciate all the comments and suggestions. Will be working on this tomorrow. Thanks to all.
 

Eljefegeneo

Still trying to learn
Local time
Yesterday, 16:31
Joined
Jan 10, 2011
Messages
904
after disabling the filter, do a Requery, then go to the desired record:
Code:
Me.FilterOn = False
Me.Requery
DoCmd.GoToRecord acActiveDataObject, Me.Name, acGoTo, 7
This merely brings me back to the first record in the table. Going to try another suggestion. Just thought you wiould like to know my result on this.
 

theDBguy

I’m here to help
Staff member
Local time
Yesterday, 16:31
Joined
Oct 29, 2018
Messages
21,467
Been busy and I do appreciate all the comments and suggestions. Will be working on this tomorrow. Thanks to all.
Hi. Just curious, did you try out my demo? Was it the same as what you're trying to do?
 

zeroaccess

Active member
Local time
Yesterday, 18:31
Joined
Jan 30, 2020
Messages
671
The issue is highlighted in #3 by Paul. The form has been opened with a WHERE clause. The form's recordsource contains only one record if ID is the key field.

Options are
1 Open the form with a filter, not a where clause
2 Open the form with no filter/where but with openargs and then in the load event position the record to be displayed
3 Open the form with no filter/where clause, and in the procedure opening the form, position the record to be displayed
4 After displaying the single record, change the form's recordsource and then go to the desired record
5 Something else that I can't think of :)
6 Add a criteria to the record source query for the ID, so it gets the record # from a control or TempVar. Don't change records per instance of the form - do a form close and open again with a different record ID.
 

Eljefegeneo

Still trying to learn
Local time
Yesterday, 16:31
Joined
Jan 10, 2011
Messages
904
Okay, unless I am misreading the problem, I really don't understand it. I said it earlier, I tried clearing the filter and it worked for me. So, just to make sure I wasn't going crazy, I created a small demo. Please let me know what I am missing. Thanks!
Demo works fine, except if the next record is missing. That should nto be a problem. Not trying to make this too complicated but I plan just to show if an error message occurs, that the user has to go to another method of opening a record through a report. Unless there is an easy fix to missing numbers.
 

theDBguy

I’m here to help
Staff member
Local time
Yesterday, 16:31
Joined
Oct 29, 2018
Messages
21,467
Demo works fine, except if the next record is missing. That should nto be a problem. Not trying to make this too complicated but I plan just to show if an error message occurs, that the user has to go to another method of opening a record through a report. Unless there is an easy fix to missing numbers.
Okay, thanks for checking it out. I was just trying to demonstrate that using Me.FilterOn=False, like I said earlier, worked for me; but you said it didn't work for you, so I guess it was just a bit of miscommunication.
 

Users who are viewing this thread

Top Bottom