Results 1 to 23 of 23

Thread: [RESOLVED] VB6 with Access 97 for multiuser system

  1. #1

    Thread Starter
    New Member
    Join Date
    Apr 2007
    Posts
    8

    Resolved [RESOLVED] VB6 with Access 97 for multiuser system

    Hi Everyone,
    This is not a joke. I know we are in the year 2007 and what I am going to talk about is compeletly obsolete.

    Here is my scenario.

    My boss wants me to write a VB6 application that saves and retreives data from an Access 97 database for approx 6 - 7 users.

    MY have managed to write it. OK....

    But my problem is that I am having too much records and table locks (like error 3262 Table in use and error 3008) when I save data to a table.

    This is the code I am using to insert a new record:
    vb Code:
    1. On Error GoTo Err_ErrorHandler
    2.    
    3.     Dim rs As dao.Recordset
    4.        
    5.     If theSerial = "" Then Exit Sub
    6.        
    7.     Set rs = db.OpenRecordset("Results", dbOpenDynaset, dbOptimistic)
    8.     rs.AddNew
    9.     rs("DateTime") = Now
    10.     rs("Serial") = theSerial
    11.     rs("ProductID") = prod.prodID
    12.     rs("Passed") = passed
    13.     rs("Comments") = comments
    14.     rs("OperatorID") = MainWindow.GetUserId
    15.     rs("Firmware") = BaseName(prod.firmware)
    16.     rs.Update
    17.     rs.Close
    18.  
    19.    
    20. Exit_ErrorHandler:
    21.     ' de-initialise our object variables
    22.     Set rs = Nothing
    23.     Exit Sub
    24.    
    25. Err_ErrorHandler:
    26.     ' display error message and error number
    27.     MsgBox Err.Description, vbExclamation, "Error #" & Err.Number
    28.     Resume Exit_ErrorHandler
    Am I using the correct connection mothods (i.e DAO) for a multiuser system? Is there a better option?

    Can please someone give me some hints and I am completely new to this topic?

    Thanks in advance
    Last edited by Hack; Apr 13th, 2007 at 07:36 AM. Reason: Added VB Highlight Tags

  2. #2
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: VB6 with Access 97 for multiuser system

    Welcome to the forums.

    First, DAO should not be used as that technology falls well within the definition of ancient. To connect to your database, you should be using ADO.

    Second, MS Access has been known to have issues in a multi-user environment, but, for 6 or 7 people, it shouldn't be too much of a problem providing all of them aren't doing the same thing at the same time.

  3. #3

    Thread Starter
    New Member
    Join Date
    Apr 2007
    Posts
    8

    Re: VB6 with Access 97 for multiuser system

    May I ask you one last thing please?
    Have you got a link to a code snippet where I can see how to implement ADO?

    I know that this may seem funny, but I am learning to the fly with this project.

    Thanks

  4. #4
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: VB6 with Access 97 for multiuser system

    How about an ADO Tutorial?

  5. #5
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: VB6 with Access 97 for multiuser system

    With Access 97 you may want to stay with DAO since it native to that version. The table lock is unnecessary because you are locking the entire table just to add a record. Dont do that. Either use a SQL statement that will return a blank recordset or .Execute the SQL statement of an INSERT INTO action type.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  6. #6
    Lively Member
    Join Date
    Feb 2007
    Posts
    99

    Re: VB6 with Access 97 for multiuser system

    In order to have record locking work right you have to add these two lines right after the recordset in opened

    Code:
    rs.movelast
    rs.movefirst
    Don't ask me why, but if you add those two lines your problem will be solved.

  7. #7
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: VB6 with Access 97 for multiuser system

    No, you still dont need to open a recordset to Add a new record. Recordsets are for retrieving data and not inserting it.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  8. #8
    Lively Member
    Join Date
    Feb 2007
    Posts
    99

    Re: VB6 with Access 97 for multiuser system

    Quote Originally Posted by RobDog888
    No, you still dont need to open a recordset to Add a new record. Recordsets are for retrieving data and not inserting it.
    Reread his original post. He is getting record lock errors. That occurs with '97 databases when you don't have the two lines I suggested because DAO locks a bunch of records instead of just the one a user is actually using. The code he posted is only the error handler and not the entire application.

  9. #9
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: VB6 with Access 97 for multiuser system

    Yes, and reread as the code is opening the entire table to add a record. You dont need to have a recordset to add a record like I previously pointed out.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  10. #10
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    Re: VB6 with Access 97 for multiuser system

    The locking is caused by using a recordset. As there are no records being returned, why open a recordset.

    Instead of "fixing" something that is wrong anyway, why not simply use the correct method instead?

  11. #11
    Lively Member
    Join Date
    Feb 2007
    Posts
    99

    Re: VB6 with Access 97 for multiuser system

    Quote Originally Posted by si_the_geek
    The locking is caused by using a recordset. As there are no records being returned, why open a recordset.

    Instead of "fixing" something that is wrong anyway, why not simply use the correct method instead?
    Because he IS using a recordset and needs to to perform OTHER tasks. Not just the task in the code posted. Are you saying that there is NEVER a need to open a recordset?
    Last edited by lewmur; Apr 13th, 2007 at 12:00 PM.

  12. #12
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    Re: VB6 with Access 97 for multiuser system

    Of course I'm not... you need a recordset if you want to get data from the database.

    In the code posted the recordset is opened, not read (only added to), and then closed.

    By definition, the same recordset cannot be used anywhere else - so it is pointless to use it in this case.

  13. #13
    Lively Member
    Join Date
    Feb 2007
    Posts
    99

    Re: VB6 with Access 97 for multiuser system

    Quote Originally Posted by si_the_geek
    Of course I'm not... you need a recordset if you want to get data from the database.

    In the code posted the recordset is opened, not read (only added to), and then closed.

    By definition, the same recordset cannot be used anywhere else - so it is pointless to use it in this case.
    The CODE POSTED is NOT what is causing his problem. It obviously isn't solving it either but the two lines I suggested, used in the right place, will solve it.
    Last edited by lewmur; Apr 13th, 2007 at 12:11 PM.

  14. #14
    A SQL Server fool GaryMazzone's Avatar
    Join Date
    Aug 2005
    Location
    Dover,NH
    Posts
    7,493

    Re: VB6 with Access 97 for multiuser system

    Yes the code posted is causing the error. If you are only going to add records to the table then there is no need to cause all the network traffic in bringing back all the records from the table just to say never mind all the data here I'm just going to add a new record to the table. The better solution is to create an Insert statement for the table and excute that on the connection object. Cleaner and quicker. If you look at the code that was posted the recordset was opened only to add the new record that is a waste of resources.
    Sometimes the Programmer
    Sometimes the DBA

    Mazz1

  15. #15
    Lively Member
    Join Date
    Feb 2007
    Posts
    99

    Re: VB6 with Access 97 for multiuser system

    Quote Originally Posted by GaryMazzone
    Yes the code posted is causing the error. If you are only going to add records to the table then there is no need to cause all the network traffic in bringing back all the records from the table just to say never mind all the data here I'm just going to add a new record to the table. The better solution is to create an Insert statement for the table and excute that on the connection object. Cleaner and quicker. If you look at the code that was posted the recordset was opened only to add the new record that is a waste of resources.
    Where in his post does it say that he is ONLY adding records? If he was only adding records he wouldn't be getting record locks. You can't lock a record that doesn't already exist. In order to UPDATE records, you want the record being updated locked but not a whole bunch of other records. And that is what happens if you don't use the two lines.

  16. #16
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: VB6 with Access 97 for multiuser system

    Quote Originally Posted by lewmur
    Because he IS using a recordset and needs to to perform OTHER tasks. Not just the task in the code posted. Are you saying that there is NEVER a need to open a recordset?
    Ok, things need to calm down and no yelling in caps in your posts.

    The procedure is self contained so there is no need to use a recordset since the procedure is only for adding a record, not retrieving or searching or anything else. Just executing an "insert into" sql statement is all that is needed here.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  17. #17
    Lively Member
    Join Date
    Feb 2007
    Posts
    99

    Re: VB6 with Access 97 for multiuser system

    Quote Originally Posted by RobDog888
    Ok, things need to calm down and no yelling in caps in your posts.

    The procedure is self contained so there is no need to use a recordset since the procedure is only for adding a record, not retrieving or searching or anything else. Just executing an "insert into" sql statement is all that is needed here.
    If the procedure is the entire application, you would be correct. If, OTOH, it isn't, which I fully believe to be the case, then he needs the two lines. He stated in his post that there was also a need to "retrieve" records. There is no provision for that in the code posted.

  18. #18
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: VB6 with Access 97 for multiuser system

    This is the code I am using to insert a new record:
    He doesnt need those two lines in this procedure which is what we all have been stating. Now if he has other issues in his app somewhere then that code should be posted too but not until after the changes are made to help reduce any conflicting errors during debugging.

    If he needs to retrieve records in some other procedure then it more then likely looks the same as this procedure. So the openrecordset arguments wil need to be changed so they are optimized for just retrieving records and not opening the rs with as editable. This alone will prevent the lock on the table too. Reading records will not lock a table if opened correctly.

    The rs.MoveLast and rs.MoveFirst are to initialize and fully populate the rs because of the DAO bug issue where it wont return a correct recordset count until that is done.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  19. #19
    Banned randem's Avatar
    Join Date
    Oct 2002
    Location
    Maui, Hawaii
    Posts
    11,385

    Re: VB6 with Access 97 for multiuser system

    If you want to use correct Multi-User code and solve some of your other issues look here

  20. #20

    Thread Starter
    New Member
    Join Date
    Apr 2007
    Posts
    8

    Re: VB6 with Access 97 for multiuser system

    Oh my God!!!!

    Ok.. ok... I was the culprit. I was the one who started it.

    Thanks a lot for your replies. I really appreciate it.

    Basically, I think I managed to solve the problem by using a db.execute command and inserting the sql. Obviously, I could not have made it without the replies I got.

    I am only having a slight problem. Now that I am unsing sql statement, I am getting errors when a user enters a single quote(') or double-quote(") in the comments field. The sql statement gets messed up big time.

    Is that a smart way to fix such quotations so the sql statement does not get messed up.

    Please do not fight!! OK!! keke..

  21. #21
    Banned randem's Avatar
    Join Date
    Oct 2002
    Location
    Maui, Hawaii
    Posts
    11,385

    Re: VB6 with Access 97 for multiuser system

    The best way is to eliminate it from the string before inserting

  22. #22
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: VB6 with Access 97 for multiuser system

    Also, doubling up on single quotes wil work too.

    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  23. #23
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    Re: VB6 with Access 97 for multiuser system

    See this FAQ article for how to do that 'automatically' in VB.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width