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  dBforums > PC based Database Applications > Microsoft Access > error number 1004

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 12-08-03, 03:50
damnnono_86 damnnono_86 is offline
Registered User
 
Join Date: Nov 2003
Posts: 74
error number 1004

hi, i am doing an exporting of data to excel file and after a period of time of testing my code, i will recieve this error :

error number 1004
error msg : Method 'Range' of object '_Global' failed

how can i solve/prevent this error??? when this error occurs, my exporting won't work. The error occurs at this line

"Excel.Range(Chr(Col) & Row).Select"

pls advice
nono

=------------------------------------------------------------------=
Do While Not rstCustData.EOF
Col = 65
Row = 1

For x = 0 To rstCustData.Fields.Count - 1

Excel.Range(Chr(Col) & Row).Select
Excel.ActiveCell = rstCustData.Fields(x)
Col = Col + 1

Next x

Row = Row + 1
Col = 65

rstCustData.MoveNext

Loop

=------------------------------------------------------------------=
Reply With Quote
  #2 (permalink)  
Old 12-08-03, 07:30
HomerBoo HomerBoo is offline
Registered User
 
Join Date: Sep 2003
Location: T.O.
Posts: 326
I'm not sure if 'Excel' in your code is a variable or not. Here's how I address Excel's hierarchy (I have tried a few methods, but this seems to work best for my uses):

Dim xlObject As Excel.Application
Dim xlWB As Excel.Workbook
Dim xlSheet As Excel.Worksheet

Set xlObject = New Excel.Application
Set xlWB = xlObject.Workbooks.Add
Set xlSheet = xlWB.ActiveSheet

xlSheet.Range("A1").Value = "ValueA"

etc.

BTW, if I'm reading your code correctly, you are outputting a recordset into Excel. If you're using the Excel 10.0 Object Lib (and possibly 9.0), the Range object exposes a .CopyFromRecordset method that will do that for you. All you would need to do is create the headings.
__________________
All code ADO/ADOX unless otherwise specified.
Mike.
Reply With Quote
  #3 (permalink)  
Old 12-09-03, 20:16
damnnono_86 damnnono_86 is offline
Registered User
 
Join Date: Nov 2003
Posts: 74
hi,

i have managed to solve the error, the way i place the code for retrieving the range is abit wrong organized, now everything is solved.

by the way thanks for the advice!!!

cheers
nono
Reply With Quote
Reply

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

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On