ALWAYS default to first record on form

laxster

Registered User.
Local time
Today, 17:50
Joined
Aug 25, 2009
Messages
145
I have a form that when opened needs to always default to the first record of the underlying table. How can I get it to do this?
 
Code:
Dim rst as DAO.Recordset

Set rst = Me.Recordset
rst.MoveFirst
Something like that. But you would have to test for whether it has records or not. Lookup the BOF and EOF properties of the recordset object.
 
Tables really have no order, so defaulting to the "first" record in a table is really meaningless. The best description I've ever heard is that a table id dimply a bucket of data.

What is your criteria for the "first record?" The first record/earliest record entered?

When wanting data sorted in a particular order, the usual route taken is having a query based on your table, sorting the records in it, then having your form based on the query.
 
There will always only be one record in the underlying table. Basically, the form is used to generate reports. Once the person is done, the data in the table is deleted.

When the report is generated, I have a command button which should allow the person to go back and edit the information in the form if they need to make any changes. But when they go back and edit, it takes them to a new record by default instead of the first-and-only record.
 
I think you mean recordsource of your form. Notice that when you sort the form's underlying recordset it doesn't change that of the table it's linked to.

Try what I wrote in my last post.
 
Have you looked at the Cycle property of that form? "Current Record"
 
Well, I have it set for that, but it doesn't always do that. The first time a person goes back and tries to edit it always takes them to a new record. The second and subsequent times they try to edit it behaves as expected with the cycle property set to "current record".

This is thoroughly confusing to me.
 
You're positive there isn't a piece of code that's causing it to go to a new record? ]

Did you put the code in the After_Update event of the FORM?
 
I bet there's a great reason, but what would be the bad thing about using the "docmd.gotorecord,,,acfirst" method, in a gotfocus event or something like that? Clunky I bet (as it's what the create-a-button wizard uses)...
 
Well, this form is specific to a plant. All the plants use a standardized placarding, except for one which uses a different report (though the underlying table still uses the same information. When that plant is selected from the initial form, a new form pops up using the following bit of code to make that happen:

Code:
If Plant.ListIndex > -1 And Plant.Value = "RHI" Then
     DoCmd.OpenForm "Placard generation table1 - Richmond"
End If

They can then enter all the information needed. That's really the only bit of code I have. The other forms I've created in this tool which do similar functions all work as expected.

I have nothing in after_update field, should I have something?
 
Is it the placard form you want this to take effect in or the form that re-appears (or gets the focus) after the placard form is closed?
 
PMFJI vbaInet but maybe using the Dialog mode of the OpenForm would solve the OP's issue.
 
You're included! You are a big help on this forum. You were doing fine with the OP and I did not want to step on your toes without at least saying excuse me.
 
Thanks. Doing my little best.

I didn't mind AT ALL and it was polite of you. The more advice the merrier, and for an old timer your advice is very invaluable.
 

Users who are viewing this thread

Back
Top Bottom