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" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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
>