By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,503 Members | 2,730 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,503 IT Pros & Developers. It's quick & easy.

<Object variable or With block variable not set>

P: 1
Why It throw an error of <Object variable or With block variable not set>

set objAccess = GetObject(strMdbPath)
objAccess.DoCmd.SetWarning False
objAccess.DoCmd.OpenReport strReportName, 0
'It is fine until now
objAccess.Application.Run "Function",Arg1,Arg2
'Throw the arror
<Object variable or With block variable not set>

I
Jul 26 '07 #1
Share this Question
Share on Google+
4 Replies


NeoPa
Expert Mod 15k+
P: 31,186
You have (accidentally) posted this question in the Access Articles section. This is NOT an article.
I'm moving this to the main Access questions forum.

MODERATOR.
Jul 26 '07 #2

NeoPa
Expert Mod 15k+
P: 31,186
Why It throw an error of <Object variable or With block variable not set>

set objAccess = GetObject(strMdbPath)
objAccess.DoCmd.SetWarning False
objAccess.DoCmd.OpenReport strReportName, 0
'It is fine until now
objAccess.Application.Run "Function",Arg1,Arg2
'Throw the arror
<Object variable or With block variable not set>

I
Brian, Where is this code? Is it running from within Access?
Jul 26 '07 #3

nico5038
Expert 2.5K+
P: 3,072
Hmm, did you try a different name instead of "Function" as it might be a reserved word....
I normally use "fnc" as prefix for a function to have no "reserved words" trouble.

NNic;o)
Jul 27 '07 #4

ADezii
Expert 5K+
P: 8,597
Why It throw an error of <Object variable or With block variable not set>

set objAccess = GetObject(strMdbPath)
objAccess.DoCmd.SetWarning False
objAccess.DoCmd.OpenReport strReportName, 0
'It is fine until now
objAccess.Application.Run "Function",Arg1,Arg2
'Throw the arror
<Object variable or With block variable not set>

I
The following code will run the Function fTest(Arg1, Arg2) in the C:\Test\Test.mdb External Database. The fTest(Arg1, Arg2) Function is declared Publically in a Standard Code Module. It accepts 2 String Arguments, and simply concatenates them with a space in between. The Code is of course simplistic, but my only intention is to demonstrate to you how can Run a Function or Sub-Procedure in an External Database from your Current Database. Good Luck - hope this is what you were looking for.
Expand|Select|Wrap|Line Numbers
  1. Dim strMDBPath As String
  2. 'Can also be Declared at a Modular level if needed. In its present state,
  3. 'objAccess goes out-of-scope as soon as the procedure ends.
  4. Dim objAccess As Access.Application
  5.  
  6. strMDBPath = "C:\Test\Test.mdb"
  7.  
  8. Set objAccess = CreateObject("Access.Application")
  9.  
  10. objAccess.Visible = True            'not required
  11.  
  12. objAccess.OpenCurrentDatabase strMDBPath, False
  13.  
  14. objAccess.Run "fTest", "John", "Doe"
  15.  
  16. objAccess.CloseCurrentDatabase
  17. Set objAccess = Nothing
OUTPUT:
Expand|Select|Wrap|Line Numbers
  1. John Doe
Jul 28 '07 #5

Post your reply

Sign in to post your reply or Sign up for a free account.