Results 1 to 2 of 2
  1. #1
    3 Star Lounger
    Join Date
    Feb 2004
    Location
    Kitchener, Ontario, Canada
    Posts
    228
    Thanks
    0
    Thanked 0 Times in 0 Posts

    message in a button (2002 (10.2616.2625))

    I have a form with a few text boxes and buttons on it.
    I want to set up a print button so that when you press the button a msg box pops up asking you if a certian text box should be filled in or not

    if you say yes then it should look at the text and see if it has been filled in
    if it has then the button should continue to print.
    if it is blank then it should show a message saying the the box is empty and not print but send you back to fill in the box.

    if you say no then it should look at the text and see if it has been filled in
    if it has then the button should show a message saying the the box is filled in and not print but send you back to empty the box.
    if it is blank then it should continue to print.

  2. #2
    Gold Lounger
    Join Date
    Feb 2001
    Location
    Sint Niklaas, Belgium
    Posts
    2,778
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: message in a button (2002 (10.2616.2625))

    Use the following code (with appropriate object names) in the On Click event of your button :<pre>Private Sub cmdTest_Click()
    Dim response As Long
    Response = MsgBox("Do you want to print ?", vbYesNo)
    If Response = vbYes Then
    If IsNull(Me.Text0) Then
    MsgBox "Test box is empty", vbOKOnly
    Me.Text0.SetFocus
    Exit Sub
    Else
    DoCmd.OpenReport "rptTest", acViewPreview
    End If
    Else
    If IsNull(Me.Text0) Then
    DoCmd.OpenReport "rptTest", acViewPreview
    Else
    MsgBox "Please Empty Test Box !", vbOKOnly
    Me.Text0.SetFocus
    Exit Sub
    End If
    End If
    End Sub</pre>

    This is what you asked.
    You could also empty the text box by code if the answer is NO and the text box is not empty
    Use the this code :<pre>Private Sub cmdTest_Click()
    Dim Response As Long
    Response = MsgBox("Do you want to print ?", vbYesNo)
    If Response = vbYes Then
    If IsNull(Me.Text0) Then
    MsgBox "Test box is empty", vbOKOnly
    Me.Text0.SetFocus
    Exit Sub
    Else
    DoCmd.OpenReport "rptTest", acViewPreview
    End If
    Else
    If Not IsNull(Me.Text0) Then
    Me.Text0 = ""
    End If
    DoCmd.OpenReport "rptTest", acViewPreview
    End If
    End Sub</pre>

    Francois

Posting Permissions

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