Select case with msgBox not working

Posted on 2006-03-22
Medium Priority
Last Modified: 2010-04-07
Hello, I'm trying to get confirmation from the user with a yes/no message box before I populate a grid with data from the database. The case vbNo is working correctly by exiting the procedure, yet the case VBYes is not running the code necessary to populate the grid.

Could someone please look at my code and help figure out why?

Here is the code:

Select Case MsgBox("Are you sure you want to use the schedule 70?" _
, vbYesNo)
Case vbYes
'Get 70 data to grid
On Error GoTo ErrorHandler

    CancelLogic = True
    Dim userinfo As New RetrieveGlobals.retrieveuserinfo
    Dim adCNN As ADODB.Connection
    Dim adrst As ADODB.Recordset
    Dim strcmd As String
    Dim strCnn As String
    Dim response As Variant

    sqluid = userinfo.retrieve_user()
    sqlpwd = userinfo.sql_password()
    SQLdb = userinfo.intercompany_id()
    sqlsvr = userinfo.sql_datasourcename()
    With CLIN_Filter
        .user = sqluid
        .password = sqlpwd
        .SERVER = sqlsvr
        .DataBase = SQLdb
        .Filter_Type = "CLIN"
        .Height = 7000
        .dHeight = 3750
        .Width = 8500
        .dWidth = 7800
        .addSorts = 2
        .reportCount = 4
        .sp_Name = "csp_ws_lookup_item_clin_Only70"
         response = .load_view

        CLIN_Filter_RowReturned response

    End With
    Exit Sub

    Exit Sub
Case vbNo
Exit Sub

End Select

End Sub
Question by:gogetsome
LVL 52

Accepted Solution

Carl Tawn earned 1500 total points
ID: 16262297
Its possibly erroring, your error handler doesn't do anything. Try adding a msgbox into the error handler to see if it is dropping into there.
LVL 15

Expert Comment

ID: 16262379
Replace the top like this

Select Case MsgBox("Are you sure you want to use the schedule 70?" , vbYesNo)
Case vbYes
MsgBox "I Clicked Yes"
'Get 70 data to grid
On Error GoTo ErrorHandler

I think you'll find it works
LVL 29

Expert Comment

ID: 16262958
You dont need to exit the sub if they click no because in the select case statement there is nothing to execute, below is another way to use select case for user choice

Dim Choice As Long
    Choice = MsgBox("some message", vbYesNoCancel)
    Select Case Choice
        Case vbYes
            Debug.Print "yes"
        Case vbNo
            Debug.Print "no"
        Case vbCancel
            Debug.Print "cancel"
    End Select

Author Comment

ID: 16269112
Thank you everyone for your help. Without good people like yourselves, I would not be where I am today.

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses
Course of the Month14 days, 10 hours left to enroll

840 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question