Results 1 to 3 of 3
  1. #1
    Join Date
    Jul 2009
    Posts
    47

    Unanswered: Open Form A or Form B VBA

    Hi,

    I have a button on a form that I want to open either in "normal" mode (IE record selectors and navigation buttons to browse the data) or open in add mode. The add mode will be based on whether or not the student has a record in the table that is behind the form's opening properties.

    What I have so far is this.

    Code:
    Private Sub ExSurveyButton_Click()
    On Error GoTo Err_ExSurveyButton_Click
    
        Dim stDocName As String
        Dim stLinkCriteria As String
    
        stDocName = "F_Exit_Survey"
        stLinkCriteria = "[EMIS_ID]=" & Me![EMIS_ID]
        
        If (Tbl_Exit_Survey.Form_EMIS = Me.EMIS_ID) Then
        DoCmd.OpenForm stDocName, , , stLinkCriteria
        Else
        DoCmd.OpenForm stDocName, , , stLinkCriteria, acFormAdd
        End If
        
    Exit_ExSurveyButton_Click:
        Exit Sub
    
    Err_ExSurveyButton_Click:
        MsgBox Err.Description
        Resume Exit_ExSurveyButton_Click
        
    End Sub
    I need it to work this way because even though the form opens with record 1 of 1 (a new record) it is unable to be saved because it says that another user has edited this record. However, if I click the new button then it will be able to save the new record.

    If I click the button a message pops up saying "Object required."

    Thanks.
    Last edited by apurgert; 07-29-10 at 13:49. Reason: Spelling

  2. #2
    Join Date
    May 2010
    Posts
    601
    I recommend that you make sure that the record in the current form has been saved before opening the other form.

    example:

    Code:
    
    Private Sub ExSurveyButton_Click()
    On Error GoTo Err_ExSurveyButton_Click
    
        Dim stDocName As String
        Dim stLinkCriteria As String
    
        stDocName = "F_Exit_Survey"
        stLinkCriteria = "[EMIS_ID]=" & Me![EMIS_ID]
        
        ' save record if needed before opening next form
        If Me.Dirty Then Me.Dirty = False
    
        If (Tbl_Exit_Survey.Form_EMIS = Me.EMIS_ID) Then
        DoCmd.OpenForm stDocName, , , stLinkCriteria
        Else
        DoCmd.OpenForm stDocName, , , stLinkCriteria, acFormAdd
        End If
        
    Exit_ExSurveyButton_Click:
        Exit Sub
    
    Err_ExSurveyButton_Click:
        MsgBox Err.Description
        Resume Exit_ExSurveyButton_Click
        
    End Sub
    Boyd Trimmell aka HiTechCoach HiTechCoach.com (free access stuff)
    Microsoft MVP - Access Expert
    BPM/Accounting Systems/Inventory Control/CRM
    Programming: Nine different ways to do it right, a thousand ways to do it wrong.
    Binary--it's as easy as 1-10-11

  3. #3
    Join Date
    Jul 2009
    Posts
    47
    Sorry, I think I wasn't very clear with what I was trying to do. It is actually the same form, but I just want it to open normally if there is a record for the student so that the records can be browsed. Otherwise open the same form in add mode if there are not any records for the student.

Posting Permissions

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