Results 1 to 10 of 10
  1. #1
    joecamel9166 is offline Advanced Beginner
    Windows 10 Access 2013 64bit
    Join Date
    Feb 2016
    Posts
    85

    open form within IF statement


    Ok, I have a nested If statement which decides what to do depending on the selection of a combo box.
    For some reason, the DoCmd.OpenForm isn't working. I was hoping someone could let me know why.

    Code:
    Private Sub btnEvalSave_Click()
        If IsNull(Me.cmbDisposition) Then
            If Me.Warranty = "Yes" Then
                Me.Unit_Status = "A"
                Else: Me.Unit_Status = "E"
                DoCmd.OpenReport "rptQuote", acViewNormal
            End If
        Else
            If Me.cmbDisposition = "SFR" Then
                Me.Unit_Status = "S"
                DoCmd.OpenForm "frmHours", acNormal
            Else
            End If
        
            If Me.cmbDisposition = "RNS" Then
                Me.Unit_Status = "R"
                DoCmd.OpenForm "frmHours", acNormal
                Else
                End If
            If Me.cmbDisposition = "BER" Then
                Me.Unit_Status = "E"
                DoCmd.OpenReport "rptBERQuote", acViewNormal
                Else
                End If
            If Me.cmbDisposition = "NPF" Then
                Me.Unit_Status = "R"
                DoCmd.OpenForm "frmHours", acNormal
                End If
                
        End If
        
                
        DoCmd.Save
        DoCmd.Close
    End Sub
    Thanks

  2. #2
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,518
    Which one? Is the unit_status field changing?
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    joecamel9166 is offline Advanced Beginner
    Windows 10 Access 2013 64bit
    Join Date
    Feb 2016
    Posts
    85
    Yes the unit_status is changing on all of them like it should.
    The rptQuote is opening like it should.
    Its not opening the frmHours at all and it is not saving and closing the main form.

  4. #4
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,518
    Curious. If I had to guess it's the Close (the form is opening and then closing). Add the arguments to specify what exactly should be closed.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  5. #5
    joecamel9166 is offline Advanced Beginner
    Windows 10 Access 2013 64bit
    Join Date
    Feb 2016
    Posts
    85
    Thanks, Works Perfectly.

    Little by little I'm getting the hang of this stuff!

  6. #6
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,518
    Happy to help! If you don't specify, it closes whatever object has focus.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  7. #7
    joecamel9166 is offline Advanced Beginner
    Windows 10 Access 2013 64bit
    Join Date
    Feb 2016
    Posts
    85
    I have one more question relating to this same code. This should probably be in a new thread, but if I already have values in the est_hours and est_materials, and I change the disposition, I want to change those values to 0.

    Here is the code.
    As of now those fields stay the same.
    Code:
    If Me.cmbDisposition = "SFR" Then
                Me.Unit_Status = "S"
                Me.Est_Hours.Value = "0"
                Me.Est_Materials.Value = "0"
                DoCmd.OpenForm "frmHours", acNormal
            Else
            End If

  8. #8
    ssanfu is offline Master of Nothing
    Windows XP Access 2010 32bit
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    Is Me.Est_Hours a text type field or a numeric field?
    Is Me.Est_Materials a text type field or a numeric field?

    This is a text string: "0"
    This is a number: 0

    Try
    Code:
    Me.Est_Hours = 0
    Me.Est_Materials = 0
    BTW, ".Value" is not needed since it is the default property.

  9. #9
    joecamel9166 is offline Advanced Beginner
    Windows 10 Access 2013 64bit
    Join Date
    Feb 2016
    Posts
    85
    Thanks. It's working fine now.
    BTW I have no idea how.to mark these threads as solved.

  10. #10
    ssanfu is offline Master of Nothing
    Windows XP Access 2010 32bit
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    Happy we could help..

    Just above Post #1, look for "Thread Tools". It is the bottom option.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 1
    Last Post: 02-09-2016, 07:03 AM
  2. Replies: 3
    Last Post: 05-27-2015, 01:17 PM
  3. Replies: 1
    Last Post: 03-02-2014, 01:31 PM
  4. Syntax of rs.Open Statement
    By Philosophaie in forum Access
    Replies: 5
    Last Post: 07-05-2013, 06:24 PM
  5. Replies: 1
    Last Post: 05-03-2012, 02:25 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums