Problem Statement w/ Background
I have an existing legacy vb6 program that interfaces with a MS Access .mbb file [MyDatabasePath] that has an associated User Level Security file [DataBase_MDW_SecurityFilePath] . -
Thus to get into this DB, the code provides the database itself in a full path string, AND the User Level Security 9mdw) file in a full path string, AND the UserId and PW .
The code I am working with in the legacy program (which has worked for a loooong time just fine) adds and delete records using the following connection Syntax:
Code:''<Variation for setting the Connection Properties (http://support.microsoft.com/kb/q191754)> ' ' m_adoConnection.Provider = "Microsoft.Jet.OLEDB.4.0" ' m_adoConnection.Properties("Data Source") = MyDatabasePath ' m_adoConnection.Properties("Jet OLEDB:Database Password") = "XXX" ' m_adoConnection.Properties("User ID") = "YYY" ' m_adoConnection.Properties("Password") = "ZZZ" ' m_adoConnection.Properties("Jet OLEDB:System database") = DataBase_MDW_SecurityFilePath ' ' m_adoConnection.Open ' ''</Variation for setting the Connection Properties (http://support.microsoft.com/kb/q191754)>
I am now faced with the situation of adding new fields to the TABLES in the underlying database [MYDatabasePath] - the .mdb file. Yes, I can open the (.mdb) database in MS Access Office 365 (by using a Command line with switches to specify the workgroup .mdw file) and then from within Access, add the new fields, but that is a PITAand I am looking for a vb6 programagatic way to add the new fields to the underlying database.
I dug around and found a neat little example of how to do this for a non protected database.
[insert link here] https://developerm.wordpress.com/201...ble-using-vb6/
Code:Dim DB As Database Dim RS As Recordset Private Sub Command1_Click() Call UpdateTableField("Table1", "RoomID2") End Sub Private Sub Form_Initialize() Set DB = OpenDatabase("F:\Manoj\Code\DB-AUTO-FIELD-ACCES\db3.mdb") End Sub Sub UpdateTableField(tb As String, new_fld As String) Dim CHECK As Boolean CHECK = False Dim tbl As TableDef Dim fld As Field Dim strName As String Set tbl = DB.TableDefs(tb) For Each fld In tbl.Fields If fld.Name = new_fld Then CHECK = True End If Next If CHECK = False Then Set RS = Nothing With tbl Set fld = .CreateField(new_fld, dbText) fld.DefaultValue = "" .Fields.Append fld MsgBox "new Field Created !, check table" End With Else MsgBox "Field already exist !" End If End Sub
This is a nice utility - but again, I am faced with doing this on an .mdb file that has a UserSecurityFile.mdw.
Try as I might, I can seem to get the right string to change out in that OpenDatabase Statement
I have triedCode:Set DB = OpenDatabase("F:\Manoj\Code\DB-AUTO-FIELD-ACCES\db3.mdb")
with all sorts of “” and , and ; at vaarious places but I get Syntax errors.Code:Set DB = OpenDatabase("C:\Users\MyName\Desktop\MYDatabaseFile..mdb") / WRKGRP '"MySecurityFile.mdw"
I have tried using the same structure as we use in our main code base to add records
and changed the Set DB to
but I throw a Run Time 91 Error an object block variable not setCode:Set DB = adoConnection.strConn
in the line ..
Code:Set tbl = DB.TableDefs(tb)
I'm going banannas.. Ideas .. It has been a while since I have worked with the connections and opening of databases and so I ask for help now! I think I am connecting but I am not opening and that is the reason for the bust?
Advice?




and I am looking for a vb6 programagatic way to add the new fields to the underlying database.
.. Ideas .. It has been a while since I have worked with the connections and opening of databases and so I ask for help now! I think I am connecting but I am not opening and that is the reason for the bust?
Reply With Quote
