Form in add mode

ibs001
ibs001 used Ask the Experts™
on
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"
    Else
        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_Klantcontact_Click:
    Exit Sub

Err_Klantcontact_Click:
    MsgBox Err.Description
    Resume Exit_Klantcontact_Click
   
End Sub
Comment
Watch Question

Do more with

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

Commented:
Hi,

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 ?

Nic;o)

Author

Commented:
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.
Commented:
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
into
DoCmd.OpenForm stDocName,,,,acFormAdd

Just check the parms when typing the comma's.

Nic;o)

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