D
d9pierce
Hi all,
I have a form called Frm_Company_Main and on that I have a button to
add a new contact with the following code attached to it. I want to add
a new contact and carry the values of the CompanyID and ContactTypeID
over to that form. This code works well by its own but clashes with the
next set of code that I attached to my Frm_Add_Contact. Now, if I open
add contacts it works just fine to add, delete... but when I use the
button from the Frm_Company_Main form, i get a compile error.
Could anyone help with how to change the code attached to the
Frm_Add_Contact so that it will allow me to use this control button and
open to a new record with the CompanyID and ContactTypeID from my other
form? Please help if you can. I have spent most of the night reviewing
previous posts and I see nothing in relation to this. I just want to be
able to open this form to add a new record to a Company contact without
loosing my transaction status.
The Frm_Add_Contact will only be opened from the the Command Button on
the Frm_Company_Main. Should I maybe use different code to commit or
not commit changes? If so, could you give me an example as I am new to
most of this.
Thanks so much!
Frm_Company_Main
Private Sub Add_New_Click()
DoCmd.OpenForm "Frm_Add_Contact", dataMode:=acFormAdd
With Forms("Frm_Add_Contact")
!ContactTypeID = Me.ContactTypeID
!CompanyID = Me.CompanyID
End With
End Sub
-------------------------------------------------------------------------------
Frm_Add_Contact (This is the compile error section) There is more code
if you need it and I will be happy to send!
Private Sub Form_Open(Cancel As Integer)
Dim db As DAO.Database
Dim rs As DAO.Recordset
Set db = CurrentDb
Set rs = db.OpenRecordset("SELECT * FROM Tbl_Contact", dbOpenDynaset)
Set Me.Recordset = rs
Set rs = Nothing
Set db = Nothing
End Sub
Private Sub Form_Unload(Cancel As Integer)
Dim msg As Integer
If Me.Saved Then
msg = MsgBox("Do you want to commit all changes?", vbYesNoCancel)
Select Case msg
Case vbYes
DBEngine.CommitTrans
Case vbNo
DBEngine.Rollback
Case vbCancel
Cancel = True
End Select
Else
If Me.Dirtied Then DBEngine.Rollback
End If
End Sub
I have a form called Frm_Company_Main and on that I have a button to
add a new contact with the following code attached to it. I want to add
a new contact and carry the values of the CompanyID and ContactTypeID
over to that form. This code works well by its own but clashes with the
next set of code that I attached to my Frm_Add_Contact. Now, if I open
add contacts it works just fine to add, delete... but when I use the
button from the Frm_Company_Main form, i get a compile error.
Could anyone help with how to change the code attached to the
Frm_Add_Contact so that it will allow me to use this control button and
open to a new record with the CompanyID and ContactTypeID from my other
form? Please help if you can. I have spent most of the night reviewing
previous posts and I see nothing in relation to this. I just want to be
able to open this form to add a new record to a Company contact without
loosing my transaction status.
The Frm_Add_Contact will only be opened from the the Command Button on
the Frm_Company_Main. Should I maybe use different code to commit or
not commit changes? If so, could you give me an example as I am new to
most of this.
Thanks so much!
Frm_Company_Main
Private Sub Add_New_Click()
DoCmd.OpenForm "Frm_Add_Contact", dataMode:=acFormAdd
With Forms("Frm_Add_Contact")
!ContactTypeID = Me.ContactTypeID
!CompanyID = Me.CompanyID
End With
End Sub
-------------------------------------------------------------------------------
Frm_Add_Contact (This is the compile error section) There is more code
if you need it and I will be happy to send!
Private Sub Form_Open(Cancel As Integer)
Dim db As DAO.Database
Dim rs As DAO.Recordset
Set db = CurrentDb
Set rs = db.OpenRecordset("SELECT * FROM Tbl_Contact", dbOpenDynaset)
Set Me.Recordset = rs
Set rs = Nothing
Set db = Nothing
End Sub
Private Sub Form_Unload(Cancel As Integer)
Dim msg As Integer
If Me.Saved Then
msg = MsgBox("Do you want to commit all changes?", vbYesNoCancel)
Select Case msg
Case vbYes
DBEngine.CommitTrans
Case vbNo
DBEngine.Rollback
Case vbCancel
Cancel = True
End Select
Else
If Me.Dirtied Then DBEngine.Rollback
End If
End Sub