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

    muddled if statement (Access 2000)

    How can i make my Else..If statement make look no so cumbersome? Besides the condition for previewing the report doesnt work,may be my If condition does no apply properly. Perhaps this is due to the many conditions in my If else statements. Do i have a mistake in my function CmdStockReceipt ?

    Private Sub CmdStockReceipt_Click()
    Dim f As Form
    Set f = Forms![FOrderInformation]
    If IsNull(f![LstStockReceipt]) Then
    DoCmd.Beep
    MsgBox " Please select Order first ! "
    Exit Sub
    Else
    Dim stLinkCriteria As String
    Dim stDocName As String
    stDocName = "Invoice"
    stLinkCriteria = "orderid = " & f![LstStockReceipt]
    Dim intPrint As Integer
    Dim intAnswer As Integer
    intAnswer = MsgBox(" Delete? ", vbQuestion + vbYesNo)
    If intAnswer = vbYes Then
    Application.Echo False
    CancelOrderOnOffice
    Else
    intPrint = MsgBox(" Print? ", vbQuestion + vbYesNo)
    If intPrint = vbYes Then
    FncPrint
    Else
    DoCmd.OpenReport stDocName, acPreview, , stLinkCriteria
    VisibleOrder
    Reports![invoice]![LblStockreceipt].Visible = True
    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: muddled if statement (Access 2000)

    You haven't told us what you want the code to do, and in what way it doesn't work. If you would like assistance, you'll have to be specific.

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

    Re: muddled if statement (Access 2000)

    I beg to be apologized i was not clear.
    With my code i wanted to give three option s: to delete the document, to print it or just to preview it.
    The last option, to preview the document seems to me that does not function properly.AT least the document is not opened to preview it.
    I cannot understand is it due to my code or to something else ?
    I think i better way is to use a select statement,bu then, what will be Case 2 is that case /

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

    Re: muddled if statement (Access 2000)

    The code seems to be OK, except that you never set Application.Echo True again.; this is very dangeous. For a more elegant approach, use an option group. Turn on the Wizard in the Toolbox, then add an option group to your form.
    In the first step of the wizard, specify three labels:

    Delete
    Print
    Preview

    Then click Next.
    In the second step, you can specify a default option, or none if you prefer. Then click Next.
    In the third step, Access proposes option values 1, 2 and 3. This is OK, so click Next.
    In the fourth step, keep the first option selected; you don't want to store the option value in a field. Then click Next.
    In the fifth step, you can select some layout options; I suggest using radio buttons, but you can follow your own preference. After choosing, click Next.
    In the final step, specify a caption for the option group, then click Finish.

    The option group should still be selected; activate the Other tab of the Properties window and rename it to (for instance) grpChoose. Modify the code for the command button as follows:

    Private Sub CmdStockReceipt_Click()
    If IsNull(Me!LstStockReceipt) Then
    MsgBox " Please select Order first ! "
    Me!LstStockReceipt.SetFocus
    Exit Sub
    End If

    If IsNull(Me!grpChoose) Then
    MsgBox " Please select an option first ! "
    Me!grpChoose.SetFocus
    Exit Sub
    End If

    Select Case grpChoose
    Case 1 ' Delete
    Echo False
    CancelOrderOnOffice
    Echo True
    Case 2 ' Print
    FncPrint
    Case 3 ' Preview
    DoCmd.OpenReport "Invoice", acViewPreview, , "OrderID = " & Me!LstStockReceipt
    VisibleOrder
    End Select
    End Sub

    You can't make a control on a report visible the way you try to do it; a report is different from a form. You must set the visibility of a report control in the On Format event of the section that contains the control.

Posting Permissions

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