get null from case statement

newapa

Board Regular
Joined
Sep 13, 2012
Messages
69
hi!

i'm trying to find the word emplyod and writ to differant column.
but i get null from the case statement.

Code:
Sub GetRow(sSelect As String, iRow As Long)
    Dim con As New ADODB.Connection
    Dim conString As String
    Dim RC As New ADODB.Recordset
    Dim Post As String
   
    con.Open "Provider=test; Password=123; User ID=test12; Data Source=G12"
    RC.CursorLocation = adUseServer
    RC.Open sSelect, con, adOpenForwardOnly, adLockReadOnly
   
    If RC.RecordCount + 2 > 0 Then Post = RC.Fields(0)
   
    Select Case sSelect
        Case InStr(sSelect, "EplyodA") > 0
            ThisWorkbook.Worksheets("Sheet1").Range("C" & iRow).Value = Post
        Case InStr(sSelect, "EmplyodB") > 0
            ThisWorkbook.Worksheets("Sheet1").Range("D" & iRow).Value = Post
        Case InStr(sSelect, "EmplyodC") > 0
            ThisWorkbook.Worksheets("Sheet1").Range("E" & iRow).Value = Post
        Case InStr(sSelect, "EmplyodD") > 0
            ThisWorkbook.Worksheets("Sheet1").Range("F" & iRow).Value = Post
    End Select
       
    RC.Close
    con.Close
    
End Sub
 
Sub Test()
    Dim i As Long
    Dim sSelect As String
   
    i = 1
    sSelect = "SELECT Count(1) FROM EmplyodB WHERE Name Like 'Bo%' "
 
    GetRow sSelect, i
End Sub

the case InStr(sSelect, "EmplyodB") is greater then 0 but it still jump over the ThisWorkbook.Worksheets("Sheet1").Range("C" & iRow).Value = Post??

thx in advance
 

Excel Facts

Who is Mr Spreadsheet?
Author John Walkenbach was Mr Spreadsheet until his retirement in June 2019.
Why are you using Instr?

What happens if you change to Case "EplyodA", "EmplyodB" etc
That should work for the exact text 'EmplyodA", "EmplyodB"


Code:
Select Case sSelect
        Case  "EplyodA"
            ThisWorkbook.Worksheets("Sheet1").Range("C" & iRow).Value = Post
        Case "EmplyodB"
            ThisWorkbook.Worksheets("Sheet1").Range("D" & iRow).Value = Post
        Case "EmplyodC"
            ThisWorkbook.Worksheets("Sheet1").Range("E" & iRow).Value = Post
        Case "sEmplyodD"
            ThisWorkbook.Worksheets("Sheet1").Range("F" & iRow).Value = Post
    End Select
If that doesn't work change Select sSelect to Select True.
 
Upvote 0
Norie

i allready tryied it and it still return null.

firefly2012

u solved my problem.

but big thx to both of u.
 
Upvote 0

Forum statistics

Threads
1,223,228
Messages
6,170,871
Members
452,363
Latest member
merico17

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top