Hi,
I have a number of clients that run a little program which copies certain files from a CD to a desired location of their machines. 90% of clients run the program successfuly. I have a few machines that come up with an error. The error is "Runtime Error 91, Object Variable or With Block Variable Not Set"
The function which i presume is causing the problem is shown below. If somebody can tell me why i get this message on some machines i would much appreciate it. I can't understand this problem.
Function GetNetworkConnection() As String
Dim ls_LocalName As String
Dim ls_RemoteName As String
Dim i_iX As Integer
Dim ui_cb As Long
Dim strNetworkString As String
Dim i As Integer
Dim db As Database
Dim rstLookup As Recordset
Dim strLocation As String
Dim intCounter As Integer
Dim strCompanyName() As String
Dim blankLocation As String
Dim workstationSetupLocation As String
Dim ServerSetupLocation As String
Dim strCompany As String
Dim strSupport As String
Dim strHelp As String
Dim dataLocation As String
Dim FSO As Scripting.FileSystemObject
Dim File As Scripting.File
Screen.MousePointer = vbHourglass
Set FSO = New FileSystemObject
i = 0
For i_iX = 1 To 26
ls_LocalName = Chr(64 + i_iX) + ":"
ls_RemoteName = Space(128)
ui_cb = 127
If WNetGetConnection(ls_LocalName, ls_RemoteName, ui_cb) = 0 Then
lstNetworkDrive.AddItem (ls_LocalName + " - " + ls_RemoteName)
strNetworkString = ls_LocalName & "\" & SETUP_FILE_NAME
If FileExists(strNetworkString) Then
i = i + 1
strLocation = strNetworkString
End If
If i = 2 Then
Unload Me
MsgBox "Problem: I have found SETUP.MDE on more than one network drive. Please call the Support Desk on 03 9678 9278. ", vbInformation, App.Title & " - Upgrade Installation"
End
End If
End If
Next
If i = 0 Then
strLocation = Upgrade_Install
Screen.MousePointer = vbDefault
Exit Function
ElseIf i = 1 Then
Set db = DBEngine(0).OpenDatabase(strLocation, , True)
Set rstLookup = db.OpenRecordset("SELECT Value FROM tblLookup WHERE Parameter='CompanyName'", dbOpenSnapshot)
Do Until rstLookup.EOF
lstCompany.AddItem (rstLookup!Value)
strCompany = Left$(strLocation, 3) & rstLookup!Value & "\templates"
strSupport = Left$(strLocation, 3) & rstLookup!Value & "\" & DOCS & "\" & SUPPORT
strHelp = Left$(strLocation, 3) & rstLookup!Value & "\" & DOCS & "\" & HELP
If FileExists(Left$(strLocation, 3) & rstLookup!Value & "\tcsdata.mdb"
Then
If Not FSO.FolderExists(strSupport) Then
MkDir Left$(strLocation, 3) & rstLookup!Value & "\" & DOCS
MkDir Left$(strLocation, 3) & rstLookup!Value & "\" & DOCS & "\" & SUPPORT
FSO.CopyFile App.Path & IIf(Right$(App.Path, 1) = "\", "", "\"
& "SWLT.PDF", strSupport & "\SWLT.PDF", True
Set File = FSO.GetFile(strSupport & "\SWLT.PDF"
File.Attributes = Archive
Else
If Not FileExists(strSupport & "\SWLT.PDF"
Then
FSO.CopyFile App.Path & IIf(Right$(App.Path, 1) = "\", "", "\"
& "SWLT.PDF", strSupport & "\SWLT.PDF", True
Set File = FSO.GetFile(strSupport & "\SWLT.PDF"
File.Attributes = Archive
End If
End If
End If
If FileExists(Left$(strLocation, 3) & rstLookup!Value & "\tcsdata.mdb"
Then
'If Len(Dir$(strSupport)) = 0 Then
If Not FSO.FolderExists(strHelp) Then
MkDir Left$(strLocation, 3) & rstLookup!Value & "\" & DOCS & "\" & HELP
FSO.CopyFile App.Path & IIf(Right$(App.Path, 1) = "\", "", "\"
& "ExportFields.pdf", strHelp & "\ExportFields.pdf", True
Set File = FSO.GetFile(strHelp & "\ExportFields.pdf"
File.Attributes = Archive
Else
If Not FileExists(strHelp & "\ExportFields.pdf"
Then
FSO.CopyFile App.Path & IIf(Right$(App.Path, 1) = "\", "", "\"
& "ExportFields.pdf", strSupport & "\ExportFields.pdf", True
Set File = FSO.GetFile(strHelp & "\ExportFields.pdf"
File.Attributes = Archive
End If
End If
End If
If Not Len(Dir$(strCompany & "\*.doc"
) = 0 Then
FSO.CopyFile App.Path & IIf(Right$(App.Path, 1) = "\", "", "\"
& "sdgoods.doc", strCompany & "\sdgoods.doc", True
'FileCopy App.Path & IIf(Right$(App.Path, 1) = "\", "", "\"
& "sdgoods.doc", strCompany & "\sdgoods.doc"
Set File = FSO.GetFile(strCompany & "\sdgoods.doc"
File.Attributes = Archive
End If
rstLookup.MoveNext
Loop
blankLocation = Left$(strLocation, 3) & CLIENTSIDE_FILE_NAME_BLANK
workstationSetupLocation = Left$(strLocation, 3) & WORKSTATION_SETUP
ServerSetupLocation = Left$(strLocation, 3) & SERVER_SETUP
dataLocation = Left$(strLocation, 3) & DATASOURCE_FILE_NAME_BLANK
Me.txtStages.Visible = True
Me.txtStages.Caption = "Upgrade Installation: Copying new files"
Me.Refresh
FSO.CopyFile App.Path & IIf(Right$(App.Path, 1) = "\", "", "\"
& CLIENTSIDE_FILE_NAME_BLANK, blankLocation, True
FSO.CopyFile App.Path & IIf(Right$(App.Path, 1) = "\", "", "\"
& WORKSTATION_SETUP, workstationSetupLocation, True
FSO.CopyFile App.Path & IIf(Right$(App.Path, 1) = "\", "", "\"
& SERVER_SETUP, ServerSetupLocation, True
FSO.CopyFile App.Path & IIf(Right$(App.Path, 1) = "\", "", "\"
& DATASOURCE_FILE_NAME_BLANK, dataLocation, True
Set File = FSO.GetFile(blankLocation)
File.Attributes = Archive
Set File = FSO.GetFile(workstationSetupLocation)
File.Attributes = Archive
Set File = FSO.GetFile(ServerSetupLocation)
File.Attributes = Archive
Set File = FSO.GetFile(dataLocation)
File.Attributes = Archive
Set rstLookup = Nothing
db.Close
Set File = Nothing
Set FSO = Nothing
Screen.MousePointer = vbDefault
Beep
Me.txtStages.Visible = False
Me.Refresh
MsgBox "Success! The Upgrade files have been copied successfully!", vbInformation, App.Title & " - Upgrade Install"
End
End If
Screen.MousePointer = vbDefault
GetNetworkConnection = strLocation
End Function
I have a number of clients that run a little program which copies certain files from a CD to a desired location of their machines. 90% of clients run the program successfuly. I have a few machines that come up with an error. The error is "Runtime Error 91, Object Variable or With Block Variable Not Set"
The function which i presume is causing the problem is shown below. If somebody can tell me why i get this message on some machines i would much appreciate it. I can't understand this problem.
Function GetNetworkConnection() As String
Dim ls_LocalName As String
Dim ls_RemoteName As String
Dim i_iX As Integer
Dim ui_cb As Long
Dim strNetworkString As String
Dim i As Integer
Dim db As Database
Dim rstLookup As Recordset
Dim strLocation As String
Dim intCounter As Integer
Dim strCompanyName() As String
Dim blankLocation As String
Dim workstationSetupLocation As String
Dim ServerSetupLocation As String
Dim strCompany As String
Dim strSupport As String
Dim strHelp As String
Dim dataLocation As String
Dim FSO As Scripting.FileSystemObject
Dim File As Scripting.File
Screen.MousePointer = vbHourglass
Set FSO = New FileSystemObject
i = 0
For i_iX = 1 To 26
ls_LocalName = Chr(64 + i_iX) + ":"
ls_RemoteName = Space(128)
ui_cb = 127
If WNetGetConnection(ls_LocalName, ls_RemoteName, ui_cb) = 0 Then
lstNetworkDrive.AddItem (ls_LocalName + " - " + ls_RemoteName)
strNetworkString = ls_LocalName & "\" & SETUP_FILE_NAME
If FileExists(strNetworkString) Then
i = i + 1
strLocation = strNetworkString
End If
If i = 2 Then
Unload Me
MsgBox "Problem: I have found SETUP.MDE on more than one network drive. Please call the Support Desk on 03 9678 9278. ", vbInformation, App.Title & " - Upgrade Installation"
End
End If
End If
Next
If i = 0 Then
strLocation = Upgrade_Install
Screen.MousePointer = vbDefault
Exit Function
ElseIf i = 1 Then
Set db = DBEngine(0).OpenDatabase(strLocation, , True)
Set rstLookup = db.OpenRecordset("SELECT Value FROM tblLookup WHERE Parameter='CompanyName'", dbOpenSnapshot)
Do Until rstLookup.EOF
lstCompany.AddItem (rstLookup!Value)
strCompany = Left$(strLocation, 3) & rstLookup!Value & "\templates"
strSupport = Left$(strLocation, 3) & rstLookup!Value & "\" & DOCS & "\" & SUPPORT
strHelp = Left$(strLocation, 3) & rstLookup!Value & "\" & DOCS & "\" & HELP
If FileExists(Left$(strLocation, 3) & rstLookup!Value & "\tcsdata.mdb"
If Not FSO.FolderExists(strSupport) Then
MkDir Left$(strLocation, 3) & rstLookup!Value & "\" & DOCS
MkDir Left$(strLocation, 3) & rstLookup!Value & "\" & DOCS & "\" & SUPPORT
FSO.CopyFile App.Path & IIf(Right$(App.Path, 1) = "\", "", "\"
Set File = FSO.GetFile(strSupport & "\SWLT.PDF"
File.Attributes = Archive
Else
If Not FileExists(strSupport & "\SWLT.PDF"
FSO.CopyFile App.Path & IIf(Right$(App.Path, 1) = "\", "", "\"
Set File = FSO.GetFile(strSupport & "\SWLT.PDF"
File.Attributes = Archive
End If
End If
End If
If FileExists(Left$(strLocation, 3) & rstLookup!Value & "\tcsdata.mdb"
'If Len(Dir$(strSupport)) = 0 Then
If Not FSO.FolderExists(strHelp) Then
MkDir Left$(strLocation, 3) & rstLookup!Value & "\" & DOCS & "\" & HELP
FSO.CopyFile App.Path & IIf(Right$(App.Path, 1) = "\", "", "\"
Set File = FSO.GetFile(strHelp & "\ExportFields.pdf"
File.Attributes = Archive
Else
If Not FileExists(strHelp & "\ExportFields.pdf"
FSO.CopyFile App.Path & IIf(Right$(App.Path, 1) = "\", "", "\"
Set File = FSO.GetFile(strHelp & "\ExportFields.pdf"
File.Attributes = Archive
End If
End If
End If
If Not Len(Dir$(strCompany & "\*.doc"
FSO.CopyFile App.Path & IIf(Right$(App.Path, 1) = "\", "", "\"
'FileCopy App.Path & IIf(Right$(App.Path, 1) = "\", "", "\"
Set File = FSO.GetFile(strCompany & "\sdgoods.doc"
File.Attributes = Archive
End If
rstLookup.MoveNext
Loop
blankLocation = Left$(strLocation, 3) & CLIENTSIDE_FILE_NAME_BLANK
workstationSetupLocation = Left$(strLocation, 3) & WORKSTATION_SETUP
ServerSetupLocation = Left$(strLocation, 3) & SERVER_SETUP
dataLocation = Left$(strLocation, 3) & DATASOURCE_FILE_NAME_BLANK
Me.txtStages.Visible = True
Me.txtStages.Caption = "Upgrade Installation: Copying new files"
Me.Refresh
FSO.CopyFile App.Path & IIf(Right$(App.Path, 1) = "\", "", "\"
FSO.CopyFile App.Path & IIf(Right$(App.Path, 1) = "\", "", "\"
FSO.CopyFile App.Path & IIf(Right$(App.Path, 1) = "\", "", "\"
FSO.CopyFile App.Path & IIf(Right$(App.Path, 1) = "\", "", "\"
Set File = FSO.GetFile(blankLocation)
File.Attributes = Archive
Set File = FSO.GetFile(workstationSetupLocation)
File.Attributes = Archive
Set File = FSO.GetFile(ServerSetupLocation)
File.Attributes = Archive
Set File = FSO.GetFile(dataLocation)
File.Attributes = Archive
Set rstLookup = Nothing
db.Close
Set File = Nothing
Set FSO = Nothing
Screen.MousePointer = vbDefault
Beep
Me.txtStages.Visible = False
Me.Refresh
MsgBox "Success! The Upgrade files have been copied successfully!", vbInformation, App.Title & " - Upgrade Install"
End
End If
Screen.MousePointer = vbDefault
GetNetworkConnection = strLocation
End Function