If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below. |
|
|
Thread Tools | Display Modes |
#1
|
|||
|
|||
Column Name
Hi
I am using this code to send data into excel Set rst = CurrentDb.OpenRecordset("SELECT Temp.* FROM Temp;") rst.MoveFirst Do While Not rst.EOF objSht.Cells(iRow, 1).Value = rst!main_id objSht.Cells(iRow, 2).Value = rst!year_id iRow = iRow + 1 rst.MoveNext Loop rst.Close End With But how would I modify my code if I dont know the name of the columns? objSht.Cells(iRow, 1).Value = rst!column1 objSht.Cells(iRow, 1).Value = rst!column2 objSht.Cells(iRow, 1).Value = rst!(1) objSht.Cells(iRow, 1).Value = rst!(2) Thank you all Bre-x |
#2
|
|||
|
|||
Column Name
In your example, it is the first column and second column, so:
objSht.Cells(iRow, 1).Value = rst!column1 objSht.Cells(iRow, 1).Value = rst!column2 should be: objSht.Cells(iRow, 1).Value = rst!column1 objSht.Cells(iRow, 2).Value = rst!column2 -- Arvin Meyer, MCP, MVP http://www.datastrat.com http://www.accessmvp.com http://www.mvps.org/access "Bre-x" wrote in message ... Hi I am using this code to send data into excel Set rst = CurrentDb.OpenRecordset("SELECT Temp.* FROM Temp;") rst.MoveFirst Do While Not rst.EOF objSht.Cells(iRow, 1).Value = rst!main_id objSht.Cells(iRow, 2).Value = rst!year_id iRow = iRow + 1 rst.MoveNext Loop rst.Close End With But how would I modify my code if I dont know the name of the columns? objSht.Cells(iRow, 1).Value = rst!column1 objSht.Cells(iRow, 1).Value = rst!column2 objSht.Cells(iRow, 1).Value = rst!(1) objSht.Cells(iRow, 1).Value = rst!(2) Thank you all Bre-x |
#3
|
|||
|
|||
Column Name
Thank you, Now how could I find out how many columns are there?
If rst!column3 does not exits the code stop executing: "Item not found in this collection" "Arvin Meyer [MVP]" wrote in message ... In your example, it is the first column and second column, so: objSht.Cells(iRow, 1).Value = rst!column1 objSht.Cells(iRow, 1).Value = rst!column2 should be: objSht.Cells(iRow, 1).Value = rst!column1 objSht.Cells(iRow, 2).Value = rst!column2 -- Arvin Meyer, MCP, MVP http://www.datastrat.com http://www.accessmvp.com http://www.mvps.org/access |
#4
|
|||
|
|||
Column Name
rst.Columns.Count
-- Doug Steele, Microsoft Access MVP http://www.AccessMVP.com/DJSteele (no e-mails, please!) "Bre-x" wrote in message ... Thank you, Now how could I find out how many columns are there? If rst!column3 does not exits the code stop executing: "Item not found in this collection" "Arvin Meyer [MVP]" wrote in message ... In your example, it is the first column and second column, so: objSht.Cells(iRow, 1).Value = rst!column1 objSht.Cells(iRow, 1).Value = rst!column2 should be: objSht.Cells(iRow, 1).Value = rst!column1 objSht.Cells(iRow, 2).Value = rst!column2 -- Arvin Meyer, MCP, MVP http://www.datastrat.com http://www.accessmvp.com http://www.mvps.org/access |
#5
|
|||
|
|||
Column Name
Sorry: mental lapse. It should have been
rst.Fields.Count -- Doug Steele, Microsoft Access MVP http://www.AccessMVP.com/DJSteele (no e-mails, please!) "Bre-x" wrote in message ... Thanks for your answer. I must be missing something: "Method or Data member not found" |
#6
|
|||
|
|||
Column Name
thank you!!!!!
Everything is working now!!! "Douglas J. Steele" wrote in message ... Sorry: mental lapse. It should have been rst.Fields.Count -- Doug Steele, Microsoft Access MVP http://www.AccessMVP.com/DJSteele (no e-mails, please!) "Bre-x" wrote in message ... Thanks for your answer. I must be missing something: "Method or Data member not found" |
Thread Tools | |
Display Modes | |
|
|