Form button to populate fields (1 Viewer)

miked1978

New member
Local time
Today, 11:01
Joined
May 22, 2020
Messages
25
I have a button on my main form that when clicked I want to populate 3 fields on the subform. The weird thing is I have another form that this works perfectly in, I literally copied the code and replaced the form names and the field names.

Anyway I get an error "Access cant find the field 'tbAssigned_WorkOrders_subform' referred to in your expression"

The code that works doesn't have a field on that line, just the form and subform name. I replaced it with my Assigned field just to see but I then get an error saying it cant find the OBJECT 'tbAssigned_WorkOrders_subform'


Code:
Private Sub cmd_AssignOrder_Click()

Set rsc = Forms![tbAssigned_Orders_Form]![tbAssigned_WorkOrders_subform].Form.RecordsetClone                            'Errors out here
rsc.MoveFirst  ' Because you have ran through the recordset once it ensures that you are starting back at the top.

Do While Not rsc.EOF
If rsc!Assigned = False Then

        rsc.Edit
        rsc!Assigned = True
        rsc!Assigned_User52 = fOSUserName
        rsc!Assigned_Date = Date + Time
        rsc.Update
          
    End If
rsc.MoveNext
Loop

End Sub

thoughts?
 

Gasman

Enthusiastic Amateur
Local time
Today, 16:01
Joined
Sep 21, 2011
Messages
14,059
It cannot find the form subcontrol?, not always the same as the subform name?
 

Gasman

Enthusiastic Amateur
Local time
Today, 16:01
Joined
Sep 21, 2011
Messages
14,059
The control that surrounds the subform. Click on the outer edge of the subform.
 

Isaac

Lifelong Learner
Local time
Today, 09:01
Joined
Mar 14, 2017
Messages
8,738
It's the name of the container that the subform is sitting in, embedded in, on the main form.
You have to click arouind a bit on the edges and corners of things (while watching the Property window) to get it
 

miked1978

New member
Local time
Today, 11:01
Joined
May 22, 2020
Messages
25
Got it. Same name but one had a space and the other has a "_" in the name

Thanks I really appreciate it!!!
 

Pat Hartman

Super Moderator
Staff member
Local time
Today, 12:01
Joined
Feb 19, 2002
Messages
42,990
I see a number of problems.
1. What you are doing is dangerous. It is putting data into the subform's "current" record which may not even be visible in the subform.
2. If you are going to do this, the button belongs on the subform record so you can "pull" from the main form.
3. But the bottom line is that you are duplicating data that you almost certainly do not need to duplicate. The data belongs in the parent record not the child record. That way, it exists in only one place. It would also have to be changed in only one place.
 

Users who are viewing this thread

Top Bottom