Results 1 to 3 of 3
  1. #1
    Join Date
    Sep 2005
    Location
    Utah
    Posts
    136

    Unanswered: Save written in VB without control wizard

    I have a command button that when clicked on I would like to save the current record before it opens a new form and closes the existing form.

    What I have is not working. I copied the code that is written when you use the control wizard to save a record.

    This is the event:

    Dim strFormName As String
    Dim strCriteria As String

    strFormName = "Main Form Patient"
    strCriteria = "[Patient ID]=" & Me![Patient ID] & ""
    DoCmd.OpenForm strFormName, acViewForm, , strCriteria

    On Error GoTo Err_save_Click

    DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70

    Exit_save_Click:
    Exit Sub

    Err_save_Click:
    MsgBox Err.Description
    Resume Exit_save_Click

    DoCmd.Close acForm, "Add Patient"

    Thanks!

  2. #2
    Join Date
    Jun 2005
    Location
    Richmond, Virginia USA
    Posts
    2,763
    Provided Answers: 19
    Try this:

    Dim strFormName As String
    Dim strCriteria As String

    On Error GoTo Err_save_Click

    strFormName = "Main Form Patient"
    strCriteria = "[Patient ID]=" & Me![Patient ID] & ""

    DoCmd.OpenForm strFormName, acViewForm, , strCriteria
    DoCmd.Close acForm, "Add Patient", acSaveYes


    Exit_save_Click:
    Exit Sub

    Err_save_Click:
    MsgBox Err.Description
    Resume Exit_save_Click
    Hope this helps!

    The problem with making anything foolproof...is that fools are so darn ingenious!

    All posts/responses based on Access 2003/2007

  3. #3
    Join Date
    Sep 2005
    Location
    Utah
    Posts
    136
    Thanks so much! I moved a couple of things around and I got it to work with what you gave me. Thanks again.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •