473,587 Members | 2,413 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Error opening a recordset

Seth Schrock
2,965 Recognized Expert Specialist
My goal is to see if I can open a table that is linked to another Access database so that I can test to make sure that the connection does exist and doesn't need reconnected to a different BE or just another location. It was suggested to first check if the file existed where I thought it should be and then see if I can open the recordset. If both come back true, then I'm good. Otherwise if one comes back false, then I need to reconnect to the BE. I have the code to test if the file exists and I now just need to figure out how to see if I can open the recordset.

Well, my stab at opening the recordset and trapping the error didn't work too well. I tried copying what MSDN had here, but I'm getting a Run-time error 3219: Invalid Operation on line 8 for some reason. Here is what I have:

Expand|Select|Wrap|Line Numbers
  1. Public Function Connected(strDBName As String) As Boolean
  2. Dim db As DAO.Database
  3. Dim rsTable As DAO.Recordset
  4.  
  5. 'On Error GoTo Err_SetValue
  6.  
  7. Set db = CurrentDb
  8. Set rsTable = db.OpenRecordset(strDBName, dbOpenTable)
  9.  
  10. Connected = True
  11.  
  12. Err_SetValue:
  13.     Connected = False
  14.  
  15. End Function
Line #5 is commented out so that I can see what the error is since otherwise it just skips to line #12. strDBName = tblTest which is the only table that I currently have in this test database (the name is correct).
Dec 12 '12 #1
20 9956
Seth Schrock
2,965 Recognized Expert Specialist
Never mind, I just fixed it.
Expand|Select|Wrap|Line Numbers
  1. Public Function Connected(strDBName As String) As Boolean
  2. Dim db As DAO.Database
  3. Dim rsTable As DAO.Recordset
  4.  
  5. On Error GoTo Connected_Err
  6.  
  7. Set db = CurrentDb
  8. Set rsTable = db.OpenRecordset(strDBName)
  9. rsTable.Close
  10.  
  11. Connected = True
  12.  
  13. Connected_Exit:
  14.     Set rsTable = Nothing
  15.     Set db = Nothing
  16.     Exit Function
  17.  
  18. Connected_Err:
  19.     Connected = False
  20.     Resume Connected_Exit
  21.  
  22. End Function
  23.  
I removed the , dbOpenTable from line 8 and fixed my terrible attempt at handling errors.
Dec 12 '12 #2
NeoPa
32,566 Recognized Expert Moderator MVP
I still want to know why the parameter is named strDBName? OpenRecordset() doesn't deal with databases. If you're dealing with a table then dbOpenTable shouldn't be causing any issues. If it is, then you have something else wrong that needs looking at.

In the circumstances, we need to know the exact value of strDBName if we're to determine what is still wrong with the code that removing dbOpenTable hides away. Also, is this value the name of a table you expect to be valid or not?
Dec 12 '12 #3
Seth Schrock
2,965 Recognized Expert Specialist
I can't say what I was thinking naming it strDBName. Probably because of working with the Exist function so much. I will rename it strTblName so that it makes more sense.

Currently strDBName resolves to tblTest (as stated in the first post below the code block) and it is the name of the linked table that I'm trying to test.
Dec 12 '12 #4
NeoPa
32,566 Recognized Expert Moderator MVP
Seth:
Currently strDBName resolves to tblTest (as stated in the first post below the code block) and it is the name of the linked table that I'm trying to test.
I do try not to make obvious mistakes like that Seth. It was a well-posted question and I missed some of the important information :-(

I assume that when using this value, your original code (with dbOpenTable) failed every time, even when the DB it was linked to should have been valid? This surprises me as that's not how it should behave according to my understanding.
Dec 12 '12 #5
Seth Schrock
2,965 Recognized Expert Specialist
No problem. I had missed that information in the other thread and this question was almost identical to it. I just didn't want you to think that I was ignoring your request from the other thread.

And you are correct, it errors out even if the link is fine and I can manually open the TableDef. I'm guessing from the error message that the problem isn't the link but my syntax. However I can't figure out what is wrong with it (not surprising) and you would know more about that than me. The reason I removed the dbopentable was that I read in my book how to open a recordset and that part was missing so I tried it without it and it worked. That is also how I figured out the problem with my error trapping.
Dec 12 '12 #6
NeoPa
32,566 Recognized Expert Moderator MVP
There was absolutely nothing wrong with your error trapping Seth. You now just have a more verbose version of the same thing (essentially). Many would recommend that such things are done visibly and explicitly in order to be clear what is going on, but the previous version should work fine. The only missing element from the version in the other thread was closing the newly opened recordset on success, which is now handled fine.

As for the table opening code, I would consider using :
Expand|Select|Wrap|Line Numbers
  1. Set rsTable = db.TableDefs(strTblName).OpenRecordset()
This is a variant specifically for opening tables from the table object itself.
Dec 12 '12 #7
Seth Schrock
2,965 Recognized Expert Specialist
The problem with my error trapping in the OP was that the Err_SetValue code was processed even if there was no error. The biggest difference is that I now have the Exit Function prior to the Connected_Err: code so if there is no error the function will end prior to reaching the Connected = False.

I also just realized that since the error that I was receiving before was a run-time error, it had to be value oriented not syntax oriented. Otherwise it would have been a compile error. Is my understanding of this correct?

And your code work perfectly. I am new to working with Recordsets in VBA (at least with having an understanding of it). What is the difference between Set rsTable = db.OpenRecordse t(strDBName) and Set rsTable = db.TableDefs(st rTblName).OpenR ecordset()? I know there has to be one. You said the later "is a variant specifically for opening tables from the table object itself." What is the other for? I assume yours is more what I need in this case?
Dec 12 '12 #8
NeoPa
32,566 Recognized Expert Moderator MVP
My best advice is to check through the Help page Seth (Type OpenRecordset then press F1). This can be run from a Database or Connection (where, clearly, some type of table or query still needs to be specified) or a TableDef or QueryDef object where this is already specified so needn't be included as a parameter.

BTW You're quite right about the Error trapping code. I overlooked that aspect. The Exit Sub would indeed have been necessary for it to work correctly.

Seth:
I also just realized that since the error that I was receiving before was a run-time error, it had to be value oriented not syntax oriented. Otherwise it would have been a compile error. Is my understanding of this correct?
That makes sense to me. I cannot state categorically that it is always so, but I would certainly consider it to be a good indication at least.
Dec 12 '12 #9
Seth Schrock
2,965 Recognized Expert Specialist
F1 didn't tell me much as the .Recordset() came up with the same page on both commands and TableDefs didn't tell me much either. Oh well, maybe I will come across it reading my Programmer's Reference Guide (if I ever get to it).
Dec 12 '12 #10

Sign in to post your reply or Sign up for a free account.

Similar topics

3
6677
by: g_mx6 | last post by:
I am not sure what I am doing wrong. I am trying to open a DSNLess connection and retrieve the data in an Excel sheet using ASP. Shouldnt be this complicated but I've been trying to get this to work. I have a named range called Sheet1. Please assist me in this. Below is the CODE and ERROR. <% '************CODE Dim oConn, oRs
8
5258
by: Drew | last post by:
This is a weird error, it seems if we reboot the web server, which is also the SQL server, I get this error, ADODB.Recordset (0x800A0E7A) Provider cannot be found. It may not be properly installed. /swvtc/CliDrAppts/detailDrAppts.asp, line 31 Now line 31 of my asp page is the connection string, so there is nothing that I can do to get my...
1
1425
by: Nagarajan | last post by:
Hello, I am trying to open an application as a VS . NET Project . I get this error every time "Cannot create the offline cache in C:\Documents and Settings\TEMP\My Documents\Visual StudioProjects\VSWebCache. Unable to create disk-based web at C:\Documents and Settings\TEMP\My Documents\Visual Studio Projects\VSWebCache because its parent web...
3
8215
by: frenchy | last post by:
I am getting this error in Adobe after struggling with a 'submit' button on an acrobat form that is in production and all the other appdev people in the office are NOT having a problem with. It submits the form to the web successfully for them, for me the button just clicks and does nothing. So we turned on my javascript debug in Adobe and...
4
5226
by: smoi | last post by:
Hello... I need help with the error I encounter when I tried to open a Table in MS SQL Server. I have the following code in VB6. Dim rs As ADODB.Recordset Set rs = New ADODB.Recordset rs.open "TableName", adoConn, adOpenKeyset, adLockOptimistic where adoConn is my Connection to the Ms SQL Server Database.
1
1762
by: =?Utf-8?B?bWF4ZG9nMzAx?= | last post by:
XP home SP2. when I tried to reload software i am getting a error. went to the registry and tried to remove the key. get the 'error opening key'. most keys open some don't. right clicked went to properties that said i did not have permission tried to change permision would not let me. even tried in safe mode administrator. Same results
4
2042
by: breadhead | last post by:
Good morning, all. I am creating an Access 2002 application to run on XP clients and I'm struggling with the task of testing whether a single-field record exists before allowing the user to add it to a look up table. I considered creating a unique index on the field in the table, but the users here would not know how to handle the error...
1
1895
by: omar.norton | last post by:
I am trying to create a from with a series of combo boxes that each query a different field (called Specific01, Specific02 etc., except the first field which is called Condition). Each combo box has a SQL statement in it's rowsource so it will only display distinct records in it's field where all the previous fields match the choices chosen...
7
2474
by: kpfunf | last post by:
Getting the following error opening a report, cannot figure out the cause: "You tried to execute a query that does not include the specified expression 'RQ_FuelQuoteReportHistory.Vendor' as part of an aggregate function" Not sure why this comes up as Vendor is not part of any aggregate function (that I know of!). The query runs fine. The...
2
1959
by: emvy681 | last post by:
I have a problem on programming, i am not that good but i can read and implement some programs. I just wanna ask help on this code Error Type: Microsoft OLE DB Provider for ODBC Drivers (0x80040E10) Too few parameters. Expected 1. /pang/view_station.asp, line 14 which is "myrec.Open sql"
0
7849
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
8215
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8347
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7973
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
8220
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
3844
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3879
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2358
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1454
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.