form from from

smartslingaro

Registered User.
Local time
Today, 09:37
Joined
Aug 23, 2019
Messages
17
Hi,
I have a form that I want to open based on record in current form. 2nd form is different table, linked by primary key in first. Need form to open with primary key on first form, like an autofill of the field. Keep getting a syntax error with this code:

Private Sub Command121_Click()
do.cmd.openform "Progress Note", acNormal,,"[Student ID]='"&Me[Student ID]&"'"
End Sub

Please help!:confused:
 
Do the capitals matter in general? that didn't work. The first line is highlighted by the debugger.
 
Hi. Is [Student ID] a Text field? Just curious...


PS. Also, to avoid potential issues when coding, try to avoid using spaces in object names.
 
no it is an auto number primary key on the first form and linked to second form/table by same field/number
 
no it is an auto number primary key on the first form and linked to second form/table by same field/number
In that case, try removing the extra quotes. For example:
Code:
DoCmd.OpenForm "Progress Note", , ,"[Student ID]="& Me.[Student ID]
Hope it helps...


PS. Don't forget to add the missing dot after Me.
 
run time erro 3075
syntax error in string in query expression '[Sutdent ID]='208'.
 
what does the acNormal mean/do?
I think it means to show the report normally, as if you opened it from the Nav Pane. It's the default anyway, so I don't think you need to specify it.
 
Private Sub Command124_Click()
DoCmd.OpenForm "Progress Note", , ,"[Student ID]="& Me.[Student ID]

This opens the form, but does not link it with student id
 
The progress note has it's own primary key, and I want the student id to prepopulate based on form where it clicked from. Maybe I set form to open to new record and this won't work? no, need it to be new record, just with student id prepopulated from previous screen.. hmmm....
 
The progress note has it's own primary key, and I want the student id to prepopulate based on form where it clicked from. Maybe I set form to open to new record and this won't work? no, need it to be new record, just with student id prepopulated from previous screen.. hmmm....
Hi. If I understand it correctly, you are talking about setting the Default Value correct? If so, there are two possible approaches you could consider. You could either use the OpenArgs argument to pass the ID, or use a form/subform setup for the second form and open it using the code we gave you.
 
Private Sub Command124_Click()
DoCmd.OpenForm "Progress Note", , ,"[Student ID]="& Me.[Student ID]

This opens the form, but does not link it with student id
You are correct. If you use a subform, Access will automatically populate the foreign key as long as the Master/Child links are properly set. With a PopUp form, you're on your own. The two forms are not connected in any way so Access has no way to know what you mean.

I use the OpenArgs to pass in the PK that needs to be used as the FK on this form.

DoCmd.OpenForm "frmProgressNote", , , , , acDialog, Me.StudentID

Then in the BeforeInsert event of the progress note form:
Code:
Me.StudentID = Me.OpenArgs

Using the BeforeInsert event will ensure that you do NOT dirty the record in the pop up form. You want the user to type at least one character so his intent to make a record is clear before you populate the FK.

PS:
1. using acDialog ensures that the user finishes the record before returning to the original form. You don't want multiple windows to be available except in special cases.
2. I took the liberty of renaming your objects using Good Practice names.
 

Users who are viewing this thread

Back
Top Bottom