Forum Discussion
davismichele11
Jun 06, 2025Copper Contributor
Access Help
I am trying to create a rather simple dbase and need a bit of guidance. I have two tables, and in the first table I have a column titled component #. The 2nd table houses all the data associated w...
Kidd_Ip
Jun 07, 2025MVP
How about this:
- Set Up a Relationship Between Tables
- Make sure your Component # in Table 1 is set up as a foreign key referencing the Component # field in Table 2.
- This ensures that only valid entries from Table 2 can be saved in Table 1.
- Use a Combo Box for Entry
- Instead of a text box, consider using a combo box in your data entry form that pulls existing component numbers from Table 2.
- If the user selects an existing component, all good. If they try to enter a new one, you’ll trigger a form.
- Create a Pop-Up Form for New Components
- In your form’s event properties, use VBA (Visual Basic for Applications) to trigger a pop-up when a non-existent Component # is entered.
- The pop-up form allows users to input the new component number and its associated data into Table 2.
- Prevent Saving if the Component # Doesn't Exist
- In the table design, use Referential Integrity so Access prevents saving invalid component numbers.
- Use BeforeUpdate VBA code in the entry form to check if the Component # exists in Table 2 before saving.
Below VBA to trigger popup:
Private Sub ComponentNumber_BeforeUpdate(Cancel As Integer)
Dim compExists As Variant
compExists = DLookup("Component#", "Table2", "Component#='" & Me.ComponentNumber & "'")
If IsNull(compExists) Then
MsgBox "Component # not found. Please add it first.", vbExclamation, "Missing Component"
DoCmd.OpenForm "NewComponentForm", , , , acFormAdd
Cancel = True
End If
End Sub
- davismichele11Jun 07, 2025Copper Contributor
Thanks! I will give this a shot on Monday