Full Version: Open form and link to other form
UtterAccess Forums > Microsoft® Access > Access Forms
flipper67
Is there a way to open a form and have it link to my other form. When you go into my DB and add a new applicant and add Basic Intervention, it brings open frmBasicIntervention. But you have to choose the applicant. I want it to know what applicant I was just adding and choose it (link it ) for me automatically. The same problem exists when I edit an existing applicant and choose review basic interventions. (Also, the same problems exist for custom intervention). Is there a code I can use when I go to interventions, so that the applicant automatically shows? DB is attached. Thanks.
AQM_UK
Not looked at the db, but, if you have basic interventions referenced to the applicant ID in the first form using
orms![frmApplicant]![ApplicantID] in the applicant ID criteria in the query bound to your basic interventions form.
This should always open the form for the record you are displaying.
Jim
flipper67
Actually, I am using the table, not a query. So, how would I go about linking the two forms? I was in frmApplication, which enters a new applicant. When I am finished with that form, it takes me to frmapplmenu where I can choose to click on the command button labeled "Enter Basic Intervention data". When I click on that and go to the form (frmBasicInterventions) I want that form to automatically display the applicant that I just entered. Currently, I have to choose the appllicant from a list. How can I change this? Thanks.
sredworb
Hi Flipper,
heck out my attachment I made for another user here at UA, perhaps you can work this linking into your db.
Let me know,
Jerry
flipper67
I tried putting in the following formula: =Forms!frmApplication!ApplicantFirstName & " " & Forms!frmApplication!ApplicantLastName
It is working the same way the form was working before. It pulls up John Smith. It still won't pull up the current applicant that I was entering. Something else needs to happen here...any suggestions? I attached the db to show you the change I made the the First Name on the basicinterventions form. Thanks.
ScottGem
This is covered in several threads here. I suggest you try searching on synchronizing forms.
There are a number of ways to do this. You can use a WHERE clause in the OpenForm method to filter the new form for the ApplicantID. You can pass the ApplicantID to the new Form using the OpenArgs argument. You can reference the ApplicantID control on the first form.
flipper67
I tried the following code in the open form event: [ApplicationID] = Forms![frmApplication]![ApplicationID] and I am getting an error that it cannot find the form frmApplication. However, that form exists. Any suggestions?
kbrewster
Is frmApplication open when this code is running?
flipper67
Seems like I tried it both ways, but let me try it again with that form open.
ScottGem
First, the Form HAS to be open. Second, where did you put that code? Just by itself that code won't do anything.
flipper67
I have the form open, but now I get another error saying I cannot assign a value to this object. Probably because of your second suggestion of where did I put it...
put it right where the cursor was when I clicked on the open event procedure. It reads like this:
Private Sub Form_Open(Cancel As Integer)
[ApplicationID] = Forms![frmApplication]![ApplicationID]
End Sub
kbrewster
Are you creating a new record in this form, or opening an existing record?
flipper67
I am not creating a new form. I just have a command button on a menu that opens up frmBasicIntervention. I want it to display the ApplicationID from the form frmApplication. What I mean is that whatever new applicant I just entered, I want their appID and name to appear in that form BasicIntervention...Currently, it displays the name John Smith, who is the first name listed in the table....
Edited by: flipper67 on Tue Jun 13 11:09:58 EDT 2006.
kbrewster
First, I said creating a new RECORD, not FORM.
Then you need to pass the appID with open args!!
ehind the command button, put this:
DoCmd.OpenForm "frmBasicIntervention" , , , , , , Me.appID
Then on frmBasicIntervention's current event put this:
If Me.NewRecord And Len(Me.OpenArgs) <> 0 Then
Me.appID = Me.OpenArgs
End If
flipper67
Oh, so sorry...
ScottGem
Like I said, that code does NOTHING. Did you try to find previous threads that show how to do this? You need to set up a filter or set the record pointer to that that record. You are doing neither.
flipper67
It didn't work. When you said to put the code behind the command button, where on there do I put it? I put it like this:
Private Sub cmdBasicIntervention_Click()
On Error GoTo Err_cmdBasicIntervention_Click
Dim stDocName As String
Dim stLinkCriteria As String
stDocName = "FRMbASICiNTERVENTION"
DoCmd.OpenForm stDocName, , , stLinkCriteria

DoCmd.OpenForm "frmBasicIntervention", , , , , , Me.ApplicationID
Exit_cmdBasicIntervention_Click:
Exit Sub
Err_cmdBasicIntervention_Click:
MsgBox Err.Description
Resume Exit_cmdBasicIntervention_Click

End Sub
kbrewster
Private Sub cmdBasicIntervention_Click()
On Error GoTo Err_cmdBasicIntervention_Click
DoCmd.OpenForm "frmBasicIntervention", , , , , , Me.ApplicationID
Exit_cmdBasicIntervention_Click:
Exit Sub
Err_cmdBasicIntervention_Click:
MsgBox Err.Description
Resume Exit_cmdBasicIntervention_Click
End Sub
ScottGem
Using the OpenArgs argument is a two step process as is explained in several other threads here on UA. First you have to open the form passing the key value as the OpenArgs argument. That's done from the previous form. The second part is done on the newly opened form. In the On Open event of that form you have to read the value passed as the OpenArgs and then use it to find the corresponding record.
This is a "lo-fi" version of UA. To view the full version with more information, formatting and images, please click here.