0

I have a data on a sheet on excel and I use SQL to query to get a dataset. This is the column the query is returning.

Sample Data

However, only items on numeric format is shown, and if the item is alphanumeric, it is blank. The resulting query is below:

enter image description here

I have formatted this column as a text and below is my connection string:

objConnectionXL.Open "Provider=Microsoft.Jet.OLEDB.4.0;" & _
    "Data Source=" & ThisWorkbook.FullName & ";" & _
        "Extended Properties=""Excel 8.0;HDR=Yes;"";"

Used query string:

sQueryFilteredValues = "Select [Reference] From [Data$] Where " & sFilterCriteria

I also tried using the query string below but it resulted the same:

sQueryFilteredValues = "Select CSTR([Reference]) From [Data$] Where " & sFilterCriteria

Recordset:

objRecordsetXL.Open sQueryFilteredValues, objConnectionXL, adOpenStatic, adLockOptimistic, adCmdText

Where: adOpenStatic = 3, adLockOptimistic = 3, adCmdText = &H1

And I use below to copy the recordset into Excel

rngRange.Offset(1, 0).CopyFromRecordset objRecordsetXL

How can I show alphanumeric items on the recordset as well? Thanks!

2
  • What's the .NumberFormat on these cells? Commented Mar 8, 2017 at 13:43
  • I've set the .NumberFormat to "@". Commented Mar 8, 2017 at 13:46

1 Answer 1

1

The problem is with the range I am copying the query results to. Only the source range has the text format. The format of the range I am copying the query results to is in general, so I guess Excel automatically converts the data into a number, based on the first cell value.

I resolved this problem by changing the format into text.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.