Results 1 to 3 of 3
  1. #1
    4 Star Lounger
    Join Date
    Feb 2002
    Posts
    537
    Thanks
    0
    Thanked 0 Times in 0 Posts

    messup with elseif (Access 2000)

    mess up with If Else


    Can somebody help me simplify my If else conditions?It seems i have a total mess up with the logical consequences

    What i want to do is to put the following questions and accordingly take the actions:

    1. Shall you delete?
    if yes, then delete, if not then:
    2. do you want an original or a copy?
    3. if you want original, shall you print it or just view it?
    4. if you want a copy, shall you print ot or just view it?

    I will be very grateful for any advice.Below is the code i am trying to construct


    Private Sub PaymentID_Click()

    ' delete the order

    Dim intAnswer As Integer
    intAnswer = MsgBox(" Delete? ", vbQuestion + vbYesNo)
    If intAnswer = vbYes Then
    Application.Echo False
    UpdateOrders "orders.paymentid = " & Screen.ActiveControl.Value
    RemoveInvoice (Me.Name)
    Me.Requery
    Application.Echo True
    Else
    ' if do not delete, what type of document do you want, original or not?
    ' if you want oeiginal, shall you print it or just view it?
    ' if you want copy, shall you print it or not?

    intAnswer = MsgBox(" original? ? ", vbQuestion + vbYesNo)
    If intAnswer = vbYes Then

    intAnswer = MsgBox("Print ?", vbQuestion + vbYesNo)
    If intAnswer = vbYes Then
    invoiceoutputWithOriginal (paymentid)
    FncPrint
    ElseIf intAnswer = vbNo Then
    invoiceoutputWithOriginal (paymentid)
    End If

    ElseIf intAnswer = vbNo Then
    intAnswer = MsgBox(" original? ? ", vbQuestion + vbYesNo)
    If intAnswer = vbYes Then
    invoiceoutput (paymentid)
    FncPrint
    ElseIf intAnswer = vbNo Then

    invoiceoutput (paymentid)
    End If
    End If
    End If

    End Sub

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: messup with elseif (Access 2000)

    I think you need to variables: one for the answer to the "Original?" question, and one for the answer to the "Print? " question. By storing the answers in separate variables, the flow of your code can be simplified.

    In the "Delete" question, you can see that it's possible to handle the answer to a MsgBox without a variable.

    If you call a MsgBox with vbYesNo, the only possible results are vbYes and vbNo, so there is no need for a construction of the form

    If intAnswer = vbYes Then
    ...
    ElseIf intAnswer = vbNo Then
    ...
    End If

    Just Else is sufficient.

    <img src=/w3timages/blueline.gif width=33% height=2>

    Private Sub PaymentID_Click()
    Dim intOriginal As Integer
    Dim intPrint As Integer
    If MsgBox(" Delete? ", vbQuestion + vbYesNo) = vbYes Then
    Application.Echo False
    UpdateOrders "orders.paymentid = " & Screen.ActiveControl.Value
    RemoveInvoice Me.Name
    Me.Requery
    Application.Echo True
    Else
    intOriginal = MsgBox(" original? ? ", vbQuestion + vbYesNo)
    intPrint = MsgBox("Print ?", vbQuestion + vbYesNo)
    If intOriginal = vbYes Then
    invoiceoutputWithOriginal paymentid
    Else
    invoiceoutput paymentid
    End If
    If intPrint Then
    FncPrint
    End If
    End If
    End Sub

  3. #3
    3 Star Lounger
    Join Date
    Jan 2001
    Location
    Wetherby, Yorkshire, England
    Posts
    283
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: messup with elseif (Access 2000)

    How are these options run - on close?
    Could you set up an option box with all the choices then run a 'Select Case' Case 1, Case 2 ... etc either on update or from a button?
    Peter

Posting Permissions

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