Linking Main form to another form

rossman66

New member
Local time
Today, 05:27
Joined
Dec 4, 2006
Messages
1
I have a table called Contact. A contact can be in the db by itself, or it can be tied to a member, or it can be tied to a facilitator or it can be a member AND a facilitator.

So I have a contact Form with all the contact related data and 2 buttons on it. One for Member and one for Facilitator. Each button should load the corresponding form. If the contact is a member (data is already in the member table for the same contactOID) then the form should populate with that information. If the contact is NOT a member, the form should be blank.

But what if I want to add a Contact record, and then add a Member record (tied to that same contact record through contactOID). I would like to be able to open Contact, click create new (>*) and enter the info. Then hit the Member form and enter all the Member info. However, when I do this I get this error:

You cannot add or change a record because a related record is required in table 'Contact'.

That doesn't make sense, since there is a record in Contact (I just created it). Do I not have the forms or tables linked correctly? Currently the Member table is linked to the Contact table through contactOID (PK in Contact - Autonumber) and there is referential integrity enforced on the relationship.
 
If you check in your Contact table, you will probably find that the record hasn't been added yet. So what you need to do before you open the Member form and in the same OnClick event, is to save the current Contact record.
 
Hello friends,

I have a similar issue, I think. I won't hijack this thread, but if it wouldn't be asking too much Lightray, could you expand on this:
and in the same OnClick event, is to save the current Contact record.

Thanks
 
Hi, I used the following bit of code to do what you need, I also was testing to see if the original (1st) form had been opened in add mode, because I then did need to save the original record, as apposed to having just used the form to edit or view a record and I have pressed the Add Button.
So I have this code in my On Click Event of my command button. you will need to subsitute variables in blue depending on your requirements.
Code:
    Dim stDocNameAdd As String
    Dim stDocNameEdit As String
    Dim stLinkCriteria As String

    stDocNameAdd = "[COLOR="Blue"]frmJobHistAdd[/COLOR]"
    stDocNameEdit = "[COLOR="blue"]frmJobHistEdit[/COLOR]"
    stLinkCriteria = [COLOR="blue"]"[EmployeeID]=" & Me![EmployeeID][/COLOR]


[COLOR="YellowGreen"]'   test if in Add mode - Current form[/COLOR]
    If Me.NewRecord = True Then
[COLOR="YellowGreen"]'   if true then save the Current new Employee record[/COLOR]
    DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70
    
    DoCmd.OpenForm stDocNameAdd, , , stLinkCriteria, acFormAdd
[COLOR="YellowGreen"]'   then open the Job History Form in Add Mode[/COLOR]
    Else
    DoCmd.OpenForm stDocNameEdit, , , stLinkCriteria, acFormEdit
[COLOR="YellowGreen"]'   Else just open the Job Form in Edit Mode[/COLOR]
    End If
I'm sure there are other solutions about. let me know how you get on.:)
 
Instead of this:
Code:
DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70
shouldn't you use this:
Code:
docmd.RunCommand acCmdSaveRecord
 

Users who are viewing this thread

Back
Top Bottom