views:

56

answers:

1

Hi,

I'm extracting some data from AS400 using excel macro. In the AS400, this particular column (Ref), shows 20100729000078154 but when I extracted it to excel, it will be 2.01007E+16. I need to hv 20100729000078154 as my final output. This is the macro that I used to extract the info from AS400 :-

Sub Extract()

Dim StrSQl As String

FromA = Format(Sheet1.Range("B3"))
FromB = Format(Sheet1.Range("B4"))
FromC = Format(Sheet1.Range("B5"))
FromD = Format(Sheet1.Range("B6"))

StrSQl = "select Cno,Itno,Ref from test "
StrSQl = StrSQl & " where Cno= " & FromA & " and Itno like " & FromB & " and "
StrSQl = StrSQl & " Ref >= " & FromC & " and  Ref <= " & FromD & " "
StrSQl = StrSQl & " order by Cno "

con = "Provider=IBMDA400;Data Source=xxx.xxx.xxx.xxx;User Id=yyyyy;Password=zzzzz"

Set Db = CreateObject("ADODB.Connection")
Set rs = CreateObject("ADODB.recordset")
Db.ConnectionString = con
Db.Open


rs.Open StrSQl, Db, 3, 3

Sheet2.Cells(1, 1).CopyFromRecordset rs

rs.Close

Set rs = Nothing
Set cn = Nothing

End Sub
+3  A: 

You can prefix an apostrophe if you're just wanting the column to display as text, something like (assuming a single apostrophe literal can be expressed as '' in iSeries SQL)...

StrSQl = "select Cno,Itno,CONCAT('''',Ref) as Ref from test "
Tahbaza
It works !!! Thank you very much. Hv been trying for days to get it right :-)
Bob