Solved

VB6 update table in Access db

Posted on 2006-10-23
3
1,330 Views
Last Modified: 2012-08-14
I have tried everything I found on the forum so far but none of them do the trick (most likely due to me not the answers).

I have a VB6 program that another person made years ago.  I have added and re-vamped to the best of my ability but now I want to call an Access update query in the source mdb and am getting this error.  

I'm getting the error
Run-time error'91'
Object variable or Wtih block variable not set.

I believe that because I have the recordset open in my VB program, it is recognizing that I have the table open once already and doesn't want me to make changes but I can manually run the agents if other people are in the program but I am only in Access.

One of the postings had a link to this microsoft KB and I think it's on the right track but can't figure out how to adapt it to my program.
http://support.microsoft.com/kb/287485/en-us

Also, on a side not, I'm just beginning to play around in SQL and was thinking that maybe I could run update query using/adapting the SQL behind the Access macros so that I don't have to open the mdb but haven't gotten that far yet so I'm definitely open to anything that goes in that direction as well.

I'm not certain what information would be most usefull so here is some of the program in case it helps:

DataEnvironment1 (Datalink properties: Share Deny None)
Provider=Microsoft.Jet.OLEDB.4.0;Data Source=H:\ROCDATA\ROCAccounting.mdb;Persist Security Info=False

ADODC is
dattechinfo
Provider=Microsoft.Jet.OLEDB.4.0;Data Source=H:\ROCDATA\ROCAccounting.mdb;Persist Security Info=False

Here is my current code behind my button on the form
 Dim db_app As Access.Application
 
 Const dbPathName = "H:\ROCDATA\ROCAccounting.mdb"
 Const acPreview = 2

 Dim Acc As Object, db As Object

 Set Acc = CreateObject("Access.Application")
 Set db = Acc.Application.DBEngine.Workspaces(0).OpenDatabase(dbPathName, 0, False)
 Acc.OpenCurrentDatabase dbPathName, False
 Acc.Visible = True

 'The next line is where it is failing.  It also fails if I make an Access macro and call that from here.
    db_app.DoCmd.OpenQuery "qryAMaketblHPWflags"
    db_app.DoCmd.OpenQuery "qryMaketblHPWUpdates"
    db_app.DoCmd.OpenQuery "qryAppendNewHPWJobsTotblTechInfo"
    db_app.DoCmd.OpenQuery "qryUpdateHPWtoTechInfo"
    db_app.DoCmd.OpenForm "MessageComplete"

 Set db = Nothing
 Set Acc = Nothing
0
Comment
Question by:VanessaTamora
  • 2
3 Comments
 
LVL 65

Expert Comment

by:Jim Horn
ID: 17788008
Most Access programmers I know in this situation would execute action queries using either ADO or DAO, and not the Access Application object.

Which in your case would be...

Set db = Acc.Application.DBEngine.Workspaces(0).OpenDatabase(dbPathName, 0, False)
with db
   .Execute "qryAMaketblHPWflags"
   .Execute "qryMaketblHPWUpdates"
   .Execute "qryAppendNewHPWJobsTotblTechInfo"
   .Execute "qryUpdateHPWtoTechInfo"
   .Execute "MessageComplete"
End With
0
 
LVL 65

Accepted Solution

by:
Jim Horn earned 500 total points
ID: 17788018
{slight correction}

Set db = Acc.Application.DBEngine.Workspaces(0).OpenDatabase(dbPathName, 0, False)
with db
   .Execute "qryAMaketblHPWflags"
   .Execute "qryMaketblHPWUpdates"
   .Execute "qryAppendNewHPWJobsTotblTechInfo"
   .Execute "qryUpdateHPWtoTechInfo"
End With

db_app.DoCmd.OpenForm "MessageComplete"  '<-- Not sure about this one, you'll have to test it
0
 
LVL 7

Expert Comment

by:yotamsher
ID: 17791092
the problem in your code, seems to be that you don't set the db_app object anywhere
it seems that you mixed two peaces of code, so either use:
      Acc.DoCmd.OpenQuery "qryAMaketblHPWflags"

or put somewhere the line:
      Set db_app = CreateObject("Access.Application")

I think this will do.
   Yotam
     
0

Featured Post

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
fix34  challenge 9 97
scoreUp challenge 14 48
bigHeights  challenge 13 55
countPairs challenge 7 58
Here we come across an interesting topic of coding guidelines while designing automation test scripts. The scope of this article will not be limited to QTP but to an overall extent of using VB Scripting for automation projects. Introduction Now…
A short article about problems I had with the new location API and permissions in Marshmallow
An introduction to basic programming syntax in Java by creating a simple program. Viewers can follow the tutorial as they create their first class in Java. Definitions and explanations about each element are given to help prepare viewers for future …
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now