Results 1 to 6 of 6
  1. #1
    Puebles is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Sep 2013
    Location
    Lansing, MI
    Posts
    14

    OpenDatabase/Table as shared

    I am new to VBA, my experience is with VFP. I am running into the problem of moving from one form to another with the same table and getting the error that the table is already open. The table is used to collect statistical data based on choices made on screen1 and displayed on screen2. A part of the code looks like this:

    Code:
    ' Code on screen1 button to display screen2
    Dim db As DAO.Database
    Dim rs1 As DAO.Recordset
    Set db = CurrentDb
    Set rs1 = db.OpenRecordset("tblControl", dbOpenTable)
    rs1.Edit
    
    ' Code goes here to calculate.
    
    rs1!PercentCancel = Round((rs1!CancelOnTime / rs1!CancelCount), 4)
    rs1.Update
    rs1.Close
    ' Screen2 (frmStats) uses tblControl in the Form Property Record Source
    DoCmd.OpenForm "frmStats"
    Note: I have reviewed many articles and advice, most of which is "How do you make it read only?" "How do you make it exclusive?" I have seen the term "Shared" used in descriptions, but never in the code. As I said, my experience is with VFP. In VFP the command would simply be: "Use tblControl Shared".



    Thank you in advance.

  2. #2
    Dal Jeanis is offline VIP
    Windows 7 32bit Access 2010 32bit
    Join Date
    May 2013
    Location
    Dallas TX
    Posts
    1,742
    If you don't need to update the second recordset, then use dbOpenSnapshot, not dbOpenTable. There are a couple of other types of recordsets. You can review the details here - http://office.microsoft.com/en-us/ac...080753713.aspx

  3. #3
    Puebles is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Sep 2013
    Location
    Lansing, MI
    Posts
    14
    I still can't get it to work. But, I did find one problem with my coding and a work around:

    1. I created small snippets of code based on examples that I have seen. Each snippet began by opening the table using the SET rs1..... code. Somtimes there were two tables and the second was opened with SET rs2. Turns out that after 12 small snippets of code were strung together I had tblControl opened last as rs1 and from a prior incident as rs2. Yep, very sloppy. I cleaned up the code and designated unique prefixes for each table. I really expected that this was why I still received the error even though I ran rs1.close prior to openeing screen 2. No such luck, and snapshot didn't work either, so....

    2. I created a query to copy the table and switched the controlling table to the new one.

    Unfortunately this is only a temporary solution. I will need to figure how to open two or more forms with the same table. This is common given the environment I am used to working in.

  4. #4
    Dal Jeanis is offline VIP
    Windows 7 32bit Access 2010 32bit
    Join Date
    May 2013
    Location
    Dallas TX
    Posts
    1,742
    Is there a technical reason you are basing your form on a recordset rather than a query? Queries don't usually cause these kinds of issues.

  5. #5
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,633
    I open mulitiple forms that pull records from the same table - they are different forms. Are you opening multiple instances of the same form?

    Along with Dal, I don't understand why you are using recordset to populate a field that should be available for reference on the form.

    Also, you are saving a calculated value - why?
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  6. #6
    Puebles is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Sep 2013
    Location
    Lansing, MI
    Posts
    14
    Habit....I learned programming on dBase3 by tacking other's code and tweeking it. I then moved to VFP. I have had little experience with queries until lately. I will have to do this now as this is a display info/read only form.

    Thanks.

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

Similar Threads

  1. Shared ODBC Connection
    By JeffGeorge in forum Queries
    Replies: 4
    Last Post: 07-10-2013, 08:10 AM
  2. OpenDatabase()
    By LegBone in forum Programming
    Replies: 3
    Last Post: 11-18-2012, 11:10 AM
  3. Replies: 2
    Last Post: 10-11-2012, 02:29 PM
  4. Shared Database
    By rafaelbatalha in forum Access
    Replies: 3
    Last Post: 02-01-2012, 11:53 AM
  5. Shared .mde (2002)
    By allenjasonbrown@gmail.com in forum Access
    Replies: 2
    Last Post: 11-08-2011, 10:52 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