I'm trying to create a simple visual basic 6 program/database that uses ms access 2007 as the back end. I have no background with vb programming. I just want to as what are the simplest way(s) in connecting vb and access? I've searched almost all over the internet on how to do this but I think I'm doing it wrong. Can anybody help me? Thanks.
问题:
回答1:
Use ADO. Theres a tutorial in the VB6 user guide about connecting VB6 to Access. http://msdn.microsoft.com/en-us/library/aa240855(v=vs.60).aspx
You will need to use an appropriate connection string for Access 2007. http://www.connectionstrings.com/access-2007
回答2:
These websites might be suitable for you. I found them using Google and searching for "vb 6 access 2007".
A suggestion from http://www.daniweb.com/software-development/visual-basic-4-5-6/threads/110825 is:
Don't use Microsoft.Jet.OLEDB.4.0 for provider. You need to use the "Microsoft.ACE.OLEDB.12.0"
The easiest way is to setup a Data Link or a Data Provider.
A suggestion from http://www.codeguru.com/forum/showthread.php?t=472469 is:
If you were using the Microsoft DAO 3.6 Object Library, try removing the reference to it and instead, set a reference to Microsoft Office 12.0 Access database engine Object Library.
The best answer from http://answers.yahoo.com/question/index?qid=20090209051024AAl8ZRC is:
Const DBNAME = "c:\customer.mdb"
Set objFSOA = CreateObject("Scripting.FileSystemObject…
If not objFSOA.FileExists(DBNAME) Then
CreateDatabase
End if
Set objConnectionA = CreateObject("ADODB.Connection")
objConnectionA.Open "Provider= Microsoft.Jet.OLEDB.4.0; " & "Data Source= " & DBNAME
Dim strSQL
strSQL = "INSERT INTO Test(col_1, col_2) VALUES (23, 'Test');"
objConnectionA.Execute(strSQL)
objConnectionA.Close
Private Sub CreateDatabase()
Dim objADOXDatabase
Set objADOXDatabase = CreateObject("ADOX.Catalog")
objADOXDatabase.Create "Provider=Microsoft.Jet.OLEDB.4.0;" & "Data Source=" & DBNAME
Set objConnectionA = CreateObject("ADODB.Connection")
objConnectionA.Open "Provider= Microsoft.Jet.OLEDB.4.0; " & "Data Source= " & DBNAME
objConnectionA.Execute "Create Table Test(col_1 number, col_2 text(10))"
objConnectionA.Close
End Sub
The suggested answer from http://www.database-answers.com/microsoft/Access-Modules-DAO/32414159/opening-access-2007-in-vb6-accessdatabaseengineexe-acedaodll.aspx is:
3) In VB6 Project|References,
a) Deselect Microsoft DAO 3.6 object library
b) Select Microsoft Office 12 access database engine object library
c) Select Microsoft Office 12 object library
4) no special code changes needed when setting db objects
I hope these suggestions and the links provided will give you some more insight into the relationship between VB 6 and Access 2007.