Results 1 to 9 of 9
  1. #1
    Juan4412 is offline Competent Performer
    Windows 7 64bit Access 2007
    Join Date
    Dec 2010
    Posts
    209

    Button to run Update Query in Diff Database

    I want to put a button on a form in DB1, and when the button is pressed, I want to update field1 in DB2 to "Richard." What VB code would I need in order to make this happen?

  2. #2
    TheShabz is offline Court Jester
    Windows XP Access 2003
    Join Date
    Feb 2010
    Posts
    1,368
    You have 2 options.
    First, you could write out a connection string to the second database. I'm not the best with connection strings so Google it or wait for someone to reply.
    Second, you could simply link to the table via the linked table manager and then treat it as if it was a local table.

  3. #3
    Juan4412 is offline Competent Performer
    Windows 7 64bit Access 2007
    Join Date
    Dec 2010
    Posts
    209
    I would rather follow the connection string route, would less clutter a db I am trying to keep clean. Can someone point me in a direction on where to start, with writing some VBA to perform this?

    I think the code would start with something like this, I just don't know what to put in on the If...Then portion....

    Private Sub Update()
    Dim IsFormLoaded As Boolean
    Dim AccessDB As DAO.Database

    IsFormLoaded = False

    If ....... Then

    End If

  4. #4
    TheShabz is offline Court Jester
    Windows XP Access 2003
    Join Date
    Feb 2010
    Posts
    1,368
    Dim db As DAO.Database
    Set
    db = DBEngine.Workspaces(0).OpenDatabase("FullPathAndFileNameOfThe2ndDb")
    db.Execute "TheQueryNameYouWishToExecute", dbFailOnError
    Set db = Nothing

    http://www.devhut.net/2010/11/08/ms-...ther-database/

  5. #5
    TheShabz is offline Court Jester
    Windows XP Access 2003
    Join Date
    Feb 2010
    Posts
    1,368
    Last edited by TheShabz; 06-23-2011 at 09:33 PM. Reason: Delete please =/

  6. #6
    Juan4412 is offline Competent Performer
    Windows 7 64bit Access 2007
    Join Date
    Dec 2010
    Posts
    209
    I am unfamiliar with this:

    Set db = DBEngine.Workspaces(0).OpenDatabase

    Are there any references that need to be added to have this code run and not error when debugging?

  7. #7
    TheShabz is offline Court Jester
    Windows XP Access 2003
    Join Date
    Feb 2010
    Posts
    1,368
    Outside of the DAO object library, I'm not sure.

  8. #8
    Juan4412 is offline Competent Performer
    Windows 7 64bit Access 2007
    Join Date
    Dec 2010
    Posts
    209
    More than likely not, I Just wanted to throw it out there to double check. Thanks for your help!

  9. #9
    Juan4412 is offline Competent Performer
    Windows 7 64bit Access 2007
    Join Date
    Dec 2010
    Posts
    209
    Would it actually be a viable option to have it pop up and ask what to update the value to? IDK if this would work, but in my update query, can I somehow have it ask, when the button is clicked what to update the value to?

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 3
    Last Post: 06-29-2012, 01:33 AM
  2. Date diff trouble
    By Cran29 in forum Queries
    Replies: 3
    Last Post: 03-11-2011, 01:02 PM
  3. Replies: 4
    Last Post: 08-30-2010, 01:24 PM
  4. Update button
    By collen in forum Access
    Replies: 3
    Last Post: 07-14-2010, 10:03 AM
  5. Check time Diff.
    By wes028 in forum Access
    Replies: 3
    Last Post: 03-08-2010, 10:05 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums