I got this working now and it works great. I made it quite simple and stuck with just some few tables, all i have is a user, addresses, emails, numbers and category table. The user table have a one to many relationship to the contact information tables and the category table have a one to many relationship to the contact information tables as well. The forms are continuous forms and the categories are determined with a query so the user can only pick a valid category for the number (phone number, mobile number, work number.) and so on.
This works really well for the needs i have right now. Then again if both the users and employees need multiple contact information details it feels like it would be an good ideé to link the user and employee table to a junction table before linking them with the contact information tables.
The table structure i have.
tblUsers
- UserID (PK - Autonumber)
- FirstName
- LastName
- DateofBrith
tblNumbers
- UserID (PK - Number)
- NumberID (PK - Autonumber)
- Number
- CategoryID (FK - Number)
tblAddresses
- UserID (PK - Number)
- AddressID (PK - Autonumber)
- Address
- City
- ZIP
- CategoryID (FK - Number)
tblEmails
- UserID (PK - Number)
- EmailID (PK - Autonumber)
- Email
- CategoryID (FK - Number)
tblCategory
- CategoryID (PK - Autonumber)
- Category
The code on the form for adding new users to the database.
Code:
Option Compare Database
Option Explicit
Private Sub btnCancel_Click()
If Me.Dirty = True Then
Me.Undo
Me.Refresh
End If
DoCmd.Close acForm, Me.Name
DoCmd.OpenForm "frmMenu", acNormal
End Sub
Private Sub btnSave_Click()
Dim intStatus As Integer
intStatus = saveCriterias()
End Sub
Private Function saveCriterias()
On Error GoTo Err_Handler
Dim CritItems As New Collection
Dim CritItem As Variant
Dim critValidated As Boolean
Dim ValidationCriteria As Integer
ValidationCriteria = 0
With CritItems '>>> 5 Items <<<'
.Add Me.txtClientKey
.Add Me.txtFirstName
.Add Me.txtLastName
.Add Me.txtDateOfBirth
.Add Me.txtRegisterdOn
End With
For Each CritItem In CritItems
If Not IsNull(CritItem) Then
ValidationCriteria = ValidationCriteria + 1
CritItem.BackColor = RGB(252, 230, 212)
Else
ValidationCriteria = ValidationCriteria - 1
CritItem.BackColor = RGB(255, 80, 80)
End If
Debug.Print ValidationCriteria
'MsgBox (ValidationCriteria)
Next CritItem
Select Case ValidationCriteria
Case Is <= 4
critValidated = False
ValidationCriteria = -1
Case 5
critValidated = True
Case Else
critValidated = False
strMsg = ("The form validation could not be confirmed.")
intResponse = MsgBox(strMsg, vbOKOnly)
GoTo Err_Handler
End Select
If critValidated = False Then
MsgBox (ValidationCriteria)
Me.Dirty = True
strMsg = ("The form does not meet all the required criterias.")
intResponse = MsgBox(strMsg, vbOKOnly)
Exit Function
Else
MsgBox (ValidationCriteria)
If ValidationCriteria = 5 Then
If Me.Dirty = True Then
Me.Dirty = False
DoCmd.Close acForm, Me.Name
DoCmd.OpenForm "frmMenu", acNormal
End If
End If
End If
Exit_Process:
Me.Refresh
Exit Function
Err_Handler:
Resume Exit_Process
End Function
Private Sub btnUnDo_Click()
Me.Undo
Me.Refresh
End Sub
Thank you for your advises, instructions and help.
//ThornofSouls