How to make 'On load' event with VB codes works for all the records in the continuous form (1 Viewer)

nax009

New member
Local time
Today, 13:12
Joined
Mar 27, 2023
Messages
15
Hello. Lately, I've been busy to make some event to run on "on load" event in my continuous form but it seems the codes work with only the first record in the form as shown in PIC_01. So my question is; How could I make my codes work for all the records. Thank you in advance :)

Here is my codes:
Code:
Private Sub Form_Load()
On Error Goto ErrorHandler
Me.field_location = CurrentProject.Path & DLookup("field_path", "table_picpath", "field_picid=" & Me.field_picidselect)
ErrorHandler:
Exit Sub
End Sub

Note: What I tried to do is to make the form automatically place a file path in field_loacation in field_location when user move their accdb file along with data folder to anywhere. Just put CurrentProject.Path with lookup for field_path from table_picpath (which I stored my pictures file path) with condition field_picid = field_picidselect.

PIC_01:
2024-01-06_09-47-44.png


PIC_02:
2024-01-06_09-43-52.png
 

The_Doc_Man

Immoderate Moderator
Staff member
Local time
Today, 01:12
Joined
Feb 28, 2001
Messages
27,186
That apparent "first record only" behavior occurs because the On_Load event doesn't deal with records. It deals with loading the "blank" controls on the form. They will be filled in by the form's On_Current event which follows the On_Load event. At the time of that On_Load event, you have not yet accessed the underlying data set. The .RecordSource is perhaps technically open, but it hasn't been queried yet. That doesn't occur until the On_Current event, and it occurs only once per record selected (not once per record displayed).

Not only that, but there is only one actual form in a continuous form.

Finally, I'm not sure I understand your goal.
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 14:12
Joined
May 7, 2009
Messages
19,243
you do not need to use Dlookup on your Form.
just Create a Query, joining yourTable with table_picpath table (join on yourTable.field_picidselect = table_picpath.field_picid).
then use this Query as RecordSource of your Form.

if you can upload a db, i can show you.
 

Pat Hartman

Super Moderator
Staff member
Local time
Today, 02:12
Joined
Feb 19, 2002
Messages
43,275
Hello. Lately, I've been busy to make some event to run on "on load" event in my continuous form but it seems the codes work with only the first record in the form as shown in PIC_01. So my question is; How could I make my codes work for all the records.
It is important to learn about form events and what event to use for which purpose

The following is a link to three videos as well as the database that was used in the video. The primary intent was to show why you should be using the Form's BeforeUpdate event for your validation code but the database can also be used to help you to understand when and why form events run. The db also includes some control level events. You can use the forms in the database or you can make your own. But, watch at least one of the videos so you can see how the event code is logged and how the form that shows the logged events works.

 

Users who are viewing this thread

Top Bottom