greetings

i am doing a database system in access and has certain function of creating and modifying an excel worksheet. i keep getting this "Run-time error '462' : Remote server machine doesn't exist or is unavailable" or sometimes "Run-time error '1004' : Method 'Range' of object '_Global' failed"..
it points to this line

Range(checker1).Select

when i click on one of my command button
as well as

ActiveWorkbook.Close True

in a different command button.

here's the code for the function that is called when some1 clicks the command button

Dim checker(5) As String
Dim insertion As Integer
OpenExcel
Set xlApp = CreateObject("Excel.Application")
Set xlBook = xlApp.Workbooks.Open("C:\Osman\ABP-FET Reference.xls")
insertion = 0
Do
    MsgBox (insertion) 'i added this for trial runs only, to check if it
                                ' follows the correct sequence
 
    Set xlSht = xlBook.Worksheets("Wafer Sort")
    Set xlRng = xlSht.Cells((insertion * 4) + 7, 3)
    checker(1) = xlRng.Value
    Set xlRng = xlSht.Cells((insertion * 4) + 7, 4)
    checker(2) = xlRng.Value
 
    Set xlSht = xlBook.Worksheets("Assembly")
    Set xlRng = xlSht.Cells((insertion * 4) + 7, 3)
    checker(3) = xlRng.Value
    Set xlRng = xlSht.Cells((insertion * 4) + 7, 4)
    checker(4) = xlRng.Value
    insertion = insertion + 1
 
Loop Until checker(1) = "" And checker(2) = "" And checker(3) = "" And checker(4) = "" ' checking for empty cells
 
insertion = ((insertion - 1) * 4) + 7
MsgBox (insertion) 'trial run purposes, to check on which row product 
                             'will be added
DC = InputBox("Please insert D/C", "Add")
PN = InputBox("Please insert P/N", "Add")
Set xlSht = xlBook.Worksheets("Wafer Sort")
xlSht.Activate
dummy = WaferSortAddProduct(insertion, DC, PN)
Set xlSht = xlBook.Worksheets("Assembly")
xlSht.Activate
dummy = AssemblyAddProduct(insertion, DC, PN)
 
xlApp.Application.UserControl = True
xlApp.Application.Visible = True
ActiveWorkbook.Close True
xlApp.Application.Visible = False
xlApp.Quit
 
Set xlRng = Nothing
Set xlSht = Nothing
Set xlBook = Nothing
Set xlApp = Nothing

OpenExcel function has the declarations for xlApp etc2..
the pointed error "Range(checker1).Select" exists in the functions "WaferSortAddProduct" and "AssemblyAddProduct", which i stored in a module, which btw, this function also exists in the same module... i use the range and select thing to modify the property of the cells, some merging, fonts, formula, borders and default values. i copy and modify it from excel recorded macros.

weird thing is, it works on the first run, then on the second run it gives the run time error, which then it works again on the third run and fails on the fourth run.. it goes on and on in that sequence..

also i can't seem to end the excel process.. i tried using all the codes that i could get my hands on but none of them actually ends the process.. after each try i have to manually end the process in task manager..

xlApp.Quit
Set xlRng = Nothing
Set xlSht = Nothing
Set xlBook = Nothing
Set xlApp = Nothing

i'm getting really frustrated over this part.. i'd really appreciate any form of help/feedback.. thanks in advance

-osman-

Dani AI

Generated

— the two errors you see (462 "Remote server..." and 1004 "Range of _Global failed") almost always come from two related issues when automating Excel from Access: unqualified references (plain Range, Selection, ActiveWorkbook, etc.) and object-lifetime/scope problems (hidden references or shadowed variables leaving COM objects alive). seeing it work on his machine points to an environment/file-specific trigger (Excel version, the workbook contents, or a variable-scoping bug that only shows up on some runs).

Fixes that consistently solve this kind of problem:

  • Never use unqualified Range/Cells/Selection. Always act through the workbook/worksheet object you created. Avoid Select/Activate entirely; write values and format ranges directly.
  • Make Excel object variables explicit and consistent in scope. Either use module-level Public variables or (better) pass the workbook/worksheet objects into your helper routines so they never rely on implicit globals.
  • Close and release in the right order: close the workbook via the workbook object, call xlApp.Quit, then Set each object to Nothing (ranges first, then sheets, then workbook, then app).
  • Use Option Explicit to catch shadowed/local declarations that hide the module-level object.

Example pattern to adopt (conceptual — adapt names to your code):

' Caller: get a sheet object and pass it in
Dim sht As Object
Set sht = xlBook.Worksheets("Wafer Sort")
Call AddProductToSheet(sht, insertion, DC, PN)

' Worker: no Select/Activate, work directly on the sheet
Sub AddProductToSheet(ByRef sht As Object, ByVal rowNum As Long, ByVal DC As String, ByVal PN As String)
  With sht
    .Cells(rowNum, 3).Value = DC
    .Cells(rowNum, 4).Value = PN
    .Range(.Cells(rowNum,3), .Cells(rowNum,4)).Borders.LineStyle = 1
  End With
End Sub

Quick debugging checklist:

  1. Log the exact string values you pass to any Range(...) call — ensure they’re valid addresses.
  2. Temporarily make xlApp.Visible = True while debugging to see which workbook/sheet is active.
  3. Remove any duplicate CreateObject/Set that might shadow a module-level xlApp.
  4. If the process stays after Quit, search Task Manager for multiple EXCEL.EXE instances and trace which code paths open them.

These steps should stop the intermittent failures and eliminate orphaned Excel processes.

Hmn, I don't seem to get that error when I run your code on my box... I wasn't sure how your ABP-FET Reference.xls file looks, so I kind of guessed, and maybe that's the issue (probably, if it's a problem with a text range), but umn..... it seems to work for me....maybe you could attach both the .xls file and the .vbs file in a .zip file.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.