I saved my database as an .mdb file and I splitted my tables successfully. But when I save my database as an .accdb (Access 2007) database, it wont work anymore. Could it be an incompatibilty with my DAO-code?
I saved my database as an .mdb file and I splitted my tables successfully. But when I save my database as an .accdb (Access 2007) database, it wont work anymore. Could it be an incompatibilty with my DAO-code?
Could it be your db isn't in a trusted folder and your VBA code is disabled? Chris Microsoft MVP -- Message posted via AccessMonster.com http://www.**--****.com/
Atfter splitting my tables in Access2007, The problem seems to occur in the following code: Public ws As Workspace Public db As Database Public tbSaldos As Recordset Set ws = DBEngine.Workspaces(0) Set db = DBEngine.Workspaces(0).Databases(0) Set tbSaldos = db.OpenRecordset("tblSaldos", DB_OPEN_TABLE) The very moment this code is reached, my database is closed, without neither warning nor error message. I think this code is still in DAO-syntax, but how to convert into ADO (if this is the problem); I have a huge lines of similar VBA-code.
Is tblSaldos now a linked table? It's probably crashing because it's getting an unhandled runtime error when it tries to open the recordset as a table type recordset if tblSaldos is a linked table. If that's the case either remove the DB_OPEN_TABLE parameter and let Jet choose the default or specify dbOpenDynaset. You may be able to use one of two other options, dbOpenSnapshot or dbOpenForwardOnly, depending on your situation. There's no error message when it crashes because there's no error handler in your procedure or the procedures that call it. Add error handling to your procedures and you'll usually get some clue what's gone wrong. Not guaranteed though. If your code uses both the DAO and ADO libraries, you need to tell Access which library to use for the recordset objects and any other objects where both libraries have the same name. Example: Public tbSaldos As DAO.Recordset Chris Microsoft MVP -- Message posted via http://www.**--****.com/
Indeed, tblSaldos is a linked table. But I need this DB_OPEN_TABLE parameter in many cases, together with an indexed field and the .seek method. It will be quit complicated to convert all this code, but maybe there are no alternatives?
You sound anxious to get started rewriting your app with ADO. Don't you like DAO? A word of advice: most things we use either library for have equivalents, so unless there's functionality that ADO has that DAO doesn't have, don't spend time on a rewrite on a functional db. You can use the seek method on a linked table if you use a recordset object that's opened on the linked table's database, not the current db. Example: Public Function linkedTblRS(strTableName As String) As DAO.Recordset On Error GoTo link_Err Dim db As Database Dim strDBName As String strDBName = Mid(CurrentDb.TableDefs(strTableName).Connect, 11) Set db = DBEngine.Workspaces(0).OpenDatabase(strDBName, False, False) Set linkedTblRS = db.OpenRecordset(strTableName, dbOpenTable) link_Exit: Set db = Nothing Exit Function link_Err: MsgBox Err.Number & vbCrLf & Err.Description Err.Clear Resume link_Exit End Function Call the above function when you need to use seek on a linked table. Like this: Public Function seekInLinkedTbl() On Error GoTo seek_Err Dim rs As DAO.Recordset Dim varBookmark As Variant Dim strLookFor As String strLookFor = "Grapes of Wrath" Set rs = linkedTblRS("tblBooks") rs.Index = "PrimaryKey" varBookmark = rs.Bookmark rs.Seek "=", strLookFor If rs.NoMatch Then rs.Bookmark = varBookmark MsgBox "Not found" Else MsgBox "Found " & strLookFor End If seek_Exit: Set rs = Nothing Exit Function seek_Err: MsgBox Err.Number & vbCrLf & Err.Description Err.Clear Resume seek_Exit End Function Chris Microsoft MVP -- Message posted via http://www.**--****.com/
You solved my problem (I indeed had to open the linked table, not the current db). Thank you very much for your excellent advise. Luciano
1.Need query to split table into 2 linked tables
I have imported a table which is very big (over 200 columns). I want to split this table into two linked (in one-to-one relationship) by an autonumber ID. Is there an efficient way to do this? I would assume I can't write out table 2 until table 1 has been completely written and the autonumber IDs assigned. Or is there a way to do it in a single query. Table 1 ID autonumber Data Table 2 ID links to ID in table 1 Data
2.Split Table to multiple tables
Dear all, I wanted to write a module to split a rather large table into multiple smaller tables. i.e. source table has 200.000 records, and I want to split it into tables by blocks of i.e. 10.000 records. The splitting is fairly simple: first 10.000 recs -> Table1, next 10.000 recs -> Table2, .... No particular order... If coded a module that uses a recordset object and then cycles record by record, counting them and copying them in a new table until it reaches the max. number of records, but this is really slow ! So I wondered if there was an other method which is perhaps more efficient. Thanks.
3.Unable to link to split table in Access 2002
The following code works in Access 2000, but does not work in Access 2002. Error is ... Method 'Connection' of object '_Current Project' failed. Can you help me fix this? I'm using Windows XP on both computers. Thanks Private Sub Form_Open(Cancel As Integer) On Error GoTo err_form_open 10 'Print CurrentProject.Connection: Stop Dim rst As New ADODB.Recordset 20 rst.Open "qryPropertyProfile", CurrentProject.Connection, _ adOpenKeyset, adLockOptimistic 'Debug.Print rst!PropertyCode txtTempPropCode.DefaultValue = rst!PropertyCode TxtTempPropName.DefaultValue = rst!PropertyName txtTempPropCode = rst!PropertyCode TxtTempPropName = rst!PropertyName 'DoCmd.Close ("qryPropertyProfile") DoCmd.Maximize DoCmd.ShowToolbar "Form View", acToolbarNo DoCmd.GoToRecord , , acNewRec DoCmd.GoToControl "Location" 'DoCmd.ShowToolbar "Menu Bar", acToolbarNo DoCmd.ShowToolbar "Web", acToolbarNo Exit Sub err_form_open: MsgBox Err.Description Resume exit_form_open exit_form_open: Exit Sub End Sub
I need to package a split Access app so that I can provide application updates in the future without stepping on the data previously saved at the user site. How do I set the pointers in Linked Table Manager so that the app will find the data after packaging and installation? Brown
5.Import Excel db and splitting table cells
Hi there, I was pointed to a discussion in this forum about splitting tables, but I don't think that a code solution is what I need, although I would be willing to entertain it some more. I searched this group and I don't see anything that sounds like it would work for me. I need to import an Excel worksheet into Access. The data is all in one column, but seperated by commas (ie, apples, oranges, bananas). I am aware of the text to columns function in Excel, but when I do this, I end up with 20+ columns and no way to make them all into one column. Is there a way to import the data into Access and put each word into a single cell? Or is there a way in Excel I can do this? Right now I'm copying my Excel column and pasting it into Word, then replacing all the commas with paragraph tags so I can get a column of words. Thanks, Christine
Users browsing this forum: No registered users and 59 guest