I've got a form frm_New_Datasheet
to enter datasheets from volunteers into a database I'm making. For the volunteer id text box txt_Vol_ID
I've got two buttons to either search for an existing volunteer or add a new one, each opening a respective form. I want the Vol_ID
from frm_Volunteers
to get passed back to frm_New_Datasheet
once I add a new volunteer.
To do this, I added the following code to my volunteer form:
Private Sub Form_AfterInsert()
If Not IsNull(Me.vol_Vol_ID) Then
Dim volVal As Double
volVal = Me.vol_Vol_ID
Forms!frm_New_Datasheet!txt_Vol_ID.Value = volVal
End If
End Sub
And it worked perfectly. Then I tried creating my 'Search for Volunteers' form, added the same code to it, but now I get the following error on both:
Run-time error -2146500594 (800f000e):
Method 'Item' of object 'Forms' failed
The debugger is highlighting the line where I set the .Value = volVal
so I've looked for other ways to call that text box but no luck yet. I've tried
Forms([frm_New_Datasheet]).[txt_Vol_ID] = volVal`
but that gives me a different error:
Run-time error '2465':
Microsoft Access can't find the field '|1' referred to in your expression
I'm pretty lost on this because I think I'm calling the other form's text box properly, and when I search for the first run-time error the best advice I've found is "Sometimes VBA is buggy and try restarting" which hasn't helped. So far this is the best idea I've had to pass the value from one form to another. If there's another place I can drop this code or another way to skin this cat I'm all ears.
Thanks!
Forms
collection. Check which form names Access sees. Paste this line of code into the Immediate window and press Enter:for each f in forms : ? f.name : next
Is "frm_New_Datasheet" listed there? – HansUp