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

    Unanswered: VB code can't get current form to close

    Can anyone tell me what's wrong with the code below?

    This is what I want to happen:
    I want to check the Last Name and First Name fields to make sure something is there, then if something is there I want the current form to be saved and a new form to open and then the current form to close.

    All of it is working fine but the current form won't close.


    Private Sub Command61_Click()

    If Me.Last_Name <> "" And Me.First_Name <> "" Then

    On Error GoTo Err_save_Click

    DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70

    Dim strFormName As String
    Dim strCriteria As String

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

    Exit_save_Click:
    Exit Sub

    Err_save_Click:
    MsgBox Err.Description
    Resume Exit_save_Click

    DoCmd.Close acForm, "Add Patient"

    Else
    MsgBox "You must enter the patient's last name and first name, or click on the Go Back button."
    End If

    End Sub

  2. #2
    Join Date
    Sep 2003
    Location
    MI
    Posts
    3,713
    Yes ... Your Close is AFTER your Resume call ... It never gets executed.
    Back to Access ... ADO is not the way to go for speed ...

  3. #3
    Join Date
    Sep 2005
    Location
    Utah
    Posts
    136
    Thanks so much for your reply, I fixed it.

  4. #4
    Join Date
    Feb 2004
    Location
    Chicago, IL
    Posts
    1,312
    Just an FYI. When I want to close the current form I use:

    DoCmd.Close acForm, Me.Name

    That way if you ever change the name of the form then the command will still work.

  5. #5
    Join Date
    Sep 2005
    Location
    Utah
    Posts
    136
    Thanks, that's a great idea. I have run into that problem several times.

Posting Permissions

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