Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Object variable or with block variable not set Problem

Status
Not open for further replies.

panadoll

Programmer
Feb 28, 2002
52
SG
I have vb Program using Microsoft Access for reports. One of my users encountered this error when she prints one of the report in the program. "Object variable or with block variable not set". This problem only occur in her pc. Right now, I can access their server from pcanywhere. Therefore, I tried running the program exe from the user's workstation through the server. Everything works fine including the printing of the report that the user is having problem with.

The following are the codes to printing the reports. Thanks for the help..

Private Sub cmdPrintJobCost_Click()
MousePointer = 11
On Error GoTo errmsg

Dim msaccess As access.Application
Dim s As Variant
Dim sql As String
Dim i As Integer, c As Integer

Set msaccess = New access.Application
'ReportPath = "G:\Newgui\Finance\FinanceReports.mdb"
With msaccess
.OpenCurrentDatabase ReportPath, False
s = .Run("This_OrderIdx", OrderIdx)
.DoCmd.OpenReport "rptJobCost", acViewPreview
.DoCmd.Maximize
.Visible = True
End With

Set msaccess = Nothing
MousePointer = 0
Exit Sub

errmsg:
msaccess.Quit acExit
Set msaccess = Nothing
MsgBox Err.Description, vbInformation, App.Title
Err = 0
Unload Me
End Sub
 
I think you have commented out(see red apostrophe in front of ReportPath) the first line of this code which leaves the variable ReportPath with no value being set. You should also Dimension this variable prior to setting its value. You then try to use the variable in the .OpenCurrentDatabase command as the first parameter:

'ReportPath = "G:\Newgui\Finance\FinanceReports.mdb"
With msaccess
.OpenCurrentDatabase ReportPath, False

Let me know if this is the problem. Bob Scriver
 
Thanks for your reply.. The reportpath is a global variable which links to the path of the *.mde.
 
Okay, that takes care of the Dim statement but what about setting its value. Are you setting that value somewhere else. Why the statement with the ' in front of it. is that just to document what the value is. The error "Object variable or with block variable not set" seems to indicate that some variable or object has not been set yet. This usually is associated with a recordset or database variable but it could be this Global variable. Check to see that there is a path string being set as the value of the Global string variable ReportPath. Bob Scriver
 
I try the same application and the same *.mde that the user has in her workstation at their server through pcanywhere. The report works well, printed out without any error. I tried it on my own workstation using the source code to run the application and the *.mde. Also no problem with it. Only that user have problem opening that report.
 
Suggestion: Give her a new copy of the .mde file with a STOP line and a RESUME line in the code as show below:

errmsg:
STOP
RESUME
msaccess.Quit acExit
Set msaccess = Nothing
MsgBox Err.Description, vbInformation, App.Title

When the error occurs rather than get the error message it will stop the code and allow for the F8 walk through of the code where the error is occurring. After pressing F8 past the Resume the code line with the problem will be highlighted.
If it is the line that I suspected earlier(.OpenCurrentDatabase ReportPath, False) either hold the mousepointer over the ReportPath variable to see it's value or go to the Debugger window and type in ?ReportPath to have its value displayed.

'ReportPath = "G:\Newgui\Finance\FinanceReports.mdb"
With msaccess
.OpenCurrentDatabase ReportPath, False

If it is not that line then at least we are a little closer to the problem. Identify the line of code and post it here and we can take a look.




Now check the value of ReportPath using the DeBugger window. Do this in the copy of the program that is causing the problem.
Bob Scriver
 
Sorry that post got scrambled somehow. I was previewing it and it posted too soon. But, it is all there so give it a try as I suggested and get back with me. Bob Scriver
 
Thanks for the suggestion, I will try it now. Thanks alot...
 
Sorry to bug in...You'll have to give her an mdb file, mde files won't allow you to see the code...

[pipe]
Daniel Vlas
Systems Consultant
danvlas@yahoo.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top