Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Visual Basic > VB 6 Visual Basic 6 > VB How-To
|
VB How-To Ask your "How do I do this with VB?" questions in this forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the VB How-To section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old September 1st, 2008, 05:39 AM
Registered User
 
Join Date: Sep 2008
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default Paramater value cancel button errors

hello every1!

I am really new to Access 2003....
Hoping somebody out there to help me with my codes...
i have the following codes, want code do exactly i need so that everytime i click the cancel in parameter value it will not debug or creates errors.

Private Sub Command110_Click()
Dim Answer As String
Dim MyNote As String

    'Prompt this message to user
    MyNote = "Sort records by Discipline." & _
              vbCrLf & "" & _
             vbCrLf & "Refer to SAUDI ARAMCO STANDARD List " & _
             "if you are not sure of the Drawing Type you want to sort." & _
             vbCrLf & "Please do not attempt to debug the codes if encountered errors." & _
             vbCrLf & "Database will display plain form if no records found, " & _
             "just right click and click on Remove Filter."

    'User response
    Answer = MsgBox(MyNote, vbOKCancel + vbInformation, "Sort Records")

     If Answer = vbOK Then
        'User should enter site name
        Answer = MsgBox("Enter Discipline", vbOKCancel + vbInformation, "Aindar")

     Else
        'Cancel event.
        DoCmd.CancelEvent
        End If

        If Answer = vbCancel Then
        'Cancel Event
        DoCmd.CancelEvent

        Else
        DoCmd.ApplyFilter , "[Discipline]= [Enter Discipline]"
        End If
End Sub

 
Old September 2nd, 2008, 01:23 PM
Friend of Wrox
 
Join Date: Nov 2004
Posts: 1,621
Thanks: 1
Thanked 3 Times in 3 Posts
Default

Not "codes," code. It is not "they are codes," but "it is code."

For readability, it is a good idea to indent everything that is part of a conceptual block. The creation of variables within a routine fit that descritpion. So rather than:
Code:
Private Sub Command110_Click()
On Error GoTo xxx
Dim Answer As String
Dim MyNote As String
...
it is better, and easier to read to have:
Code:
Private Sub Command110_Click()

    On Error GoTo xxx

    Dim Answer As String
    Dim MyNote As String
    ...
    Conceptually, carriage returns are at the end of the line. Your string concatenations will be easier to read if you lay them out that way:
Code:
    MyNote = "Sort records by Discipline." & vbCrLf & vbCrLf & _
             "Refer to SAUDI ARAMCO STANDARD List if you " & _
             "are not sure of the Drawing Type you want to sort." & vbCrLf & _
             "Please do not attempt to debug the code if you encounter errors." & vbCrLf & _
             "Database will display plain form if no records found." & vbcrlf & _
             "Just right click and click on Remove Filter."
This indentation of the End If is dangerous. It hides the fact that the If block is ending:
Code:
     If Answer = vbOK Then
        'User should enter site name
        Answer = MsgBox("Enter Discipline", vbOKCancel + vbInformation, "Aindar")

     Else
        'Cancel event.
        DoCmd.CancelEvent
        End If
Should be:
Code:
     If Answer = vbOK Then
        ' User should enter site name
        Answer = MsgBox("Enter Discipline", vbOKCancel OR vbInformation, "Aindar")

     Else
        ' Cancel event.
        DoCmd.CancelEvent
     End If
This is also bad, because you are gathering the variable to use in the next block within this block. That is confusing. Additionally, there doesn't appear to be any current event to cancel. You are in a sub routine, so you should just leave the routine without taking action if they have clicked the Cancel button on the message box (or closed the message box with the [x] in the corner:
Code:
     If Answer <> vbOK Then
        ' Cancel event.
        Exit Sub
     End If
     Then follow that with the next test, and action.
Code:
Private Sub Command110_Click()
Code:
    Dim Answer As String
    Dim MyNote As String

    ' Prompt this message to user
    MyNote = "Sort records by Discipline." & vbCrLf & vbCrLf & _
             "Refer to SAUDI ARAMCO STANDARD List if you are " & _
             "not sure of the Drawing Type you want to sort." & vbCrLf & _
             "Please do not attempt to debug the code if you encounter errors." & vbCrLf & _
             "Database will display plain form if no records found." & vbCrLf & _
             "Just right click and click on Remove Filter."

    ' User response
    Answer = MsgBox(MyNote, vbOKCancel Or vbInformation, "Sort Records")

    If Answer <> vbOK Then
        Exit Sub
    End If

    ' If we get to here, user should enter site name
    Answer = MsgBox("Enter Discipline", vbOKCancel Or vbInformation, "Aindar")

    If Answer <> vbOK Then
        Exit Sub
    End If

    DoCmd.ApplyFilter, "[Discipline]= [Enter Discipline]"

End Sub





Similar Threads
Thread Thread Starter Forum Replies Last Post
DetailsView Cancel button to redirect firblazer ASP.NET 3.5 Basics 4 June 23rd, 2008 01:23 AM
Help with date paramater gregalb Reporting Services 1 January 15th, 2008 03:55 AM
How to stop file uploading when a cancel button coolcoder2007 ASP.NET 2.0 Basics 0 October 26th, 2007 04:21 AM
Problem with cancel and next button in form method Access VBA 0 June 18th, 2005 02:11 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.