Form in add mode

ibs001 used Ask the Experts™
If i use below code i get by clicking on a form all the records. But i want to get the form in add mode, now i get in my last question the advice to use the code:
   DoCmd.OpenForm "Opdrachtbevestiging", , , , acFormAdd
But where in the below code code do i have to insert or replace this??

Private Sub Klantcontact_Click()
On Error GoTo Err_Klantcontact_Click

    Dim stDocName As String
    Dim stLinkCriteria As String

    stDocName = "Klantcontact"
        If IsNull(Me![IDBedrijf]) Then
        MsgBox "Eerst klantgegevens invoeren alvorens een klantcontact in te voeren"
        DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70
        DoCmd.OpenForm stDocName
        Form_Klantcontact.DataEntry = True
        Form_Klantcontact.AllowAdditions = True
            'Form_Opdrachtbevestiging.AllowEdits = False
            'Form_Opdrachtbevestiging.AllowEdits = True
    End If
    IDBedrijfK = Me![IDBedrijf]
    stLinkCriteria = "[IDBedrijf]=" & Me![IDBedrijf]
    DoCmd.OpenForm stDocName, , , stLinkCriteria

    Exit Sub

    MsgBox Err.Description
    Resume Exit_Klantcontact_Click
End Sub
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®


I would probably split this code and do some redesign.
1) I would create a Save button that will check or everything has been filled.
2) I would create a "Nieuw KlantContact" button that's by default disabled. After selecting a "bedrijf" e.g. with a combobox, the button can be enabled.
3) I would create a separate Update and Add button for the "bedrijf".
Again the Update button will be disabled when no "bedrijf" has been specified.

BTW I guess the message should read:
"Eerst bedrijf invullen alvorens een klantcontact in te voeren"
But using my approach you don't need this anymore...

Getting the idea ?



Nico, thanks for your advice. But isn't it possible to change something in my code, otherwise i get three buttons instead of one.

And i don't have to have a update button, but only a add one with a link criteria on IDBedrijf.
Hmm, OK can happen, but I don't see how you want to combine two forms (Form "Opdrachtbevestiging" and Form "Klantcontact") behind the button "Klantcontact"

To have a form opening in "add" mode, you just have to change:
DoCmd.OpenForm stDocName
DoCmd.OpenForm stDocName,,,,acFormAdd

Just check the parms when typing the comma's.


Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial