A Microsoft Office (Excel, Word) forum. OfficeFrustration

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.

Go Back   Home » OfficeFrustration forum » Microsoft Access » New Users
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

Column Name



 
 
Thread Tools Display Modes
  #1  
Old May 13th, 2010, 03:09 PM posted to microsoft.public.access.gettingstarted
Bre-x
external usenet poster
 
Posts: 103
Default 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  
Old May 13th, 2010, 03:34 PM posted to microsoft.public.access.gettingstarted
Arvin Meyer [MVP][_2_]
external usenet poster
 
Posts: 2,310
Default 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  
Old May 13th, 2010, 04:22 PM posted to microsoft.public.access.gettingstarted
Bre-x
external usenet poster
 
Posts: 103
Default 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  
Old May 13th, 2010, 06:30 PM posted to microsoft.public.access.gettingstarted
Douglas J. Steele[_3_]
external usenet poster
 
Posts: 3,143
Default 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  
Old May 13th, 2010, 07:05 PM posted to microsoft.public.access.gettingstarted
Douglas J. Steele[_3_]
external usenet poster
 
Posts: 3,143
Default 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  
Old May 13th, 2010, 07:17 PM posted to microsoft.public.access.gettingstarted
Bre-x
external usenet poster
 
Posts: 103
Default 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

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump


All times are GMT +1. The time now is 06:54 PM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 OfficeFrustration.
The comments are property of their posters.