Solved

VB6 update table in Access db

Posted on 2006-10-23
3
1,335 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 66

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 66

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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Displaying an arrayList in a listView using the default adapter is rarely the best solution. To get full control of your display data, and to be able to refresh it after editing, requires the use of a custom adapter.
In this post we will learn different types of Android Layout and some basics of an Android App.
Six Sigma Control Plans
Starting up a Project

707 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