Access - Linking Forms from different tables

SantasLittleHelper

Board Regular
Joined
Nov 25, 2016
Messages
77
I currently have 4 different tables that all have relationship links to their ID number. I am trying to set up a button for the user to click on to open another form that opens to the record with the same ID number.

E.g. When the button is clicked:
Open 'Form1' where 'ID' in 'Form1' is the same 'ID' in 'Form2'

I have a button on 'Form1' with a macro to open 'Form2' with the condition '="[ID]=" & [ID]' but this is currently opening 'Form2' to a New record (With a new ID)

Any help would be appreciated.
 

Excel Facts

How can you turn a range sideways?
Copy the range. Select a blank cell. Right-click, Paste Special, then choose Transpose.
Ideally I prefer not to use Subforms as I have 4 different forms/tables that are linked together with IDs. Can you think of any other way around this issue?
 
Upvote 0
I have a button on 'Form1' with a macro to open 'Form2' with the condition '="[ID]=" & [ID]' but this is currently opening 'Form2' to a New record (With a new ID)
Please post the code that you do have that is not working quite right.
 
Upvote 0
It was a macro but I've converted it to the following: - It is Opening Page 2 where ID is the same as Page 1

Code:
Private Sub cmd_Page2_Click()On Error GoTo cmd_Page2_Click_Err


    DoCmd.OpenForm "frm_Page2", acNormal, "", "[ID]=" & ID, acEdit, acNormal
    DoCmd.Close acForm, "frm_Page1"




cmd_Page2_Click_Exit:
    Exit Sub


cmd_Page2_Click_Err:
    MsgBox Error$
    Resume cmd_Page2_Click_Exit


End Sub
 
Upvote 0
So, is "ID" the exact name of the field on the Form?
If so, try:
Code:
    DoCmd.OpenForm "frm_Page2", acNormal, "", "[ID]=" & [COLOR=#ff0000]Me.[/COLOR]ID, acEdit, acNormal
 
Last edited:
Upvote 0
It worked fine for me.
Are you sure that you have an existing record in the other Table with the exact same ID?
If you don't, it will open a new record, like you are experiencing.
 
Upvote 0
Ah yes sorry. Basically when form 1 is completed, a record (with an ID) is created. The other tables that link to the other forms are all blank so I was trying to open the other forms with a record that has that ID.

E.g
Open Form 1 to a new ID
Then Open Form 2 - creating a record with the same ID number.

Is this possible?
 
Upvote 0
Ah, that is a big difference and important distinction. You are not trying to open an existing record in the other table, but add a new record that that table.
Note that in order for that to work, you need to make sure that:
- The ID field in the other table is NOT an Autonumber field
- The record does not already exist in the other table

If those things are true, this code should do what you want:
Code:
'   Capture current ID
    Dim curID As Long
    curID = Me.ID
'   Open new form
    DoCmd.OpenForm "Form2", acNormal, "", , acFormAdd, acNormal
'   Assign ID to ID in new record
    [Forms]![Form2]![ID].Value = curID
'   Close original form
    DoCmd.Close acForm, "Form1"
 
Upvote 0

Forum statistics

Threads
1,221,687
Messages
6,161,287
Members
451,695
Latest member
Doug Mize 1024

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top