Creating Access 2007+ files
-
Hi, I try to create an access 2007 or higher file. I wrote this testcode just an simple form with 2 buttons.
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles btnMake.Click
Dim dlg As New SaveFileDialogWith dlg .Filter = "Access(\*.accdb)|\*.accdb" If .ShowDialog = DialogResult.OK Then Dim cat As New ADOX.Catalog() Try cat.Create("Provider=Microsoft.ACE.OLEDB.102.0;Data Source=" & .FileName & ";Persist Security Info=True") 'cat.Create("Driver={Microsoft Access Driver (\*.mdb, \*.accdb)};DBQ=" & .FileName) Catch ex1 As Exception MsgBox(ex1.Message) If MsgBox("Is Microsoft Access Database Engine 2010 Redistributable installed?", vbQuestion Or MsgBoxStyle.YesNo) = MsgBoxResult.No Then Try Process.Start("https://www.microsoft.com/en-us/download/details.aspx?id=13255") MsgBox("Do it :)", MsgBoxStyle.SystemModal) Catch ex2 As Exception End Try End If Finally cat = Nothing End Try End If End With
End Sub
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles btnOpen.Click
Dim dlg As New OpenFileDialogWith dlg .Filter = "Access(\*.accdb)|\*.accdb" If .ShowDialog = DialogResult.OK Then Dim OLEConnection As New OleDb.OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & .FileName & ";Persist Security Info=True") OLEConnection.Open() Dim OLECommand As New OleDb.OleDbCommand("", OLEConnection) ' Before this line you can create a string that holds your build for the table structure Randomize() Dim t As Int64 = Int(Rnd() \* 100000) Try OLECommand.CommandText = "CREATE TABLE mytable" & t & " (field1 CHAR,field2 NUMBER)" OLECommand.ExecuteNonQuery() MsgBox("Table " & t & " maded") OLECommand.CommandText = "insert into mytable" & t & " values(""" & t & """, " & t & ")" OLECommand.ExecuteNonQuery() OLECommand.Connection.Close() Catch ex As Exception MsgBox(ex.Message) End Try End If End With
End Sub
Create a table works. However making a file Always fails. Can anyone gives me idaes? I've tryed installing the 32 and 64 bit version of Microsoft Access Database Engine 2010 Redistributable I'm working on a W10 machine 64bit
-
Hi, I try to create an access 2007 or higher file. I wrote this testcode just an simple form with 2 buttons.
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles btnMake.Click
Dim dlg As New SaveFileDialogWith dlg .Filter = "Access(\*.accdb)|\*.accdb" If .ShowDialog = DialogResult.OK Then Dim cat As New ADOX.Catalog() Try cat.Create("Provider=Microsoft.ACE.OLEDB.102.0;Data Source=" & .FileName & ";Persist Security Info=True") 'cat.Create("Driver={Microsoft Access Driver (\*.mdb, \*.accdb)};DBQ=" & .FileName) Catch ex1 As Exception MsgBox(ex1.Message) If MsgBox("Is Microsoft Access Database Engine 2010 Redistributable installed?", vbQuestion Or MsgBoxStyle.YesNo) = MsgBoxResult.No Then Try Process.Start("https://www.microsoft.com/en-us/download/details.aspx?id=13255") MsgBox("Do it :)", MsgBoxStyle.SystemModal) Catch ex2 As Exception End Try End If Finally cat = Nothing End Try End If End With
End Sub
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles btnOpen.Click
Dim dlg As New OpenFileDialogWith dlg .Filter = "Access(\*.accdb)|\*.accdb" If .ShowDialog = DialogResult.OK Then Dim OLEConnection As New OleDb.OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & .FileName & ";Persist Security Info=True") OLEConnection.Open() Dim OLECommand As New OleDb.OleDbCommand("", OLEConnection) ' Before this line you can create a string that holds your build for the table structure Randomize() Dim t As Int64 = Int(Rnd() \* 100000) Try OLECommand.CommandText = "CREATE TABLE mytable" & t & " (field1 CHAR,field2 NUMBER)" OLECommand.ExecuteNonQuery() MsgBox("Table " & t & " maded") OLECommand.CommandText = "insert into mytable" & t & " values(""" & t & """, " & t & ")" OLECommand.ExecuteNonQuery() OLECommand.Connection.Close() Catch ex As Exception MsgBox(ex.Message) End Try End If End With
End Sub
Create a table works. However making a file Always fails. Can anyone gives me idaes? I've tryed installing the 32 and 64 bit version of Microsoft Access Database Engine 2010 Redistributable I'm working on a W10 machine 64bit
-
Hi, I try to create an access 2007 or higher file. I wrote this testcode just an simple form with 2 buttons.
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles btnMake.Click
Dim dlg As New SaveFileDialogWith dlg .Filter = "Access(\*.accdb)|\*.accdb" If .ShowDialog = DialogResult.OK Then Dim cat As New ADOX.Catalog() Try cat.Create("Provider=Microsoft.ACE.OLEDB.102.0;Data Source=" & .FileName & ";Persist Security Info=True") 'cat.Create("Driver={Microsoft Access Driver (\*.mdb, \*.accdb)};DBQ=" & .FileName) Catch ex1 As Exception MsgBox(ex1.Message) If MsgBox("Is Microsoft Access Database Engine 2010 Redistributable installed?", vbQuestion Or MsgBoxStyle.YesNo) = MsgBoxResult.No Then Try Process.Start("https://www.microsoft.com/en-us/download/details.aspx?id=13255") MsgBox("Do it :)", MsgBoxStyle.SystemModal) Catch ex2 As Exception End Try End If Finally cat = Nothing End Try End If End With
End Sub
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles btnOpen.Click
Dim dlg As New OpenFileDialogWith dlg .Filter = "Access(\*.accdb)|\*.accdb" If .ShowDialog = DialogResult.OK Then Dim OLEConnection As New OleDb.OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & .FileName & ";Persist Security Info=True") OLEConnection.Open() Dim OLECommand As New OleDb.OleDbCommand("", OLEConnection) ' Before this line you can create a string that holds your build for the table structure Randomize() Dim t As Int64 = Int(Rnd() \* 100000) Try OLECommand.CommandText = "CREATE TABLE mytable" & t & " (field1 CHAR,field2 NUMBER)" OLECommand.ExecuteNonQuery() MsgBox("Table " & t & " maded") OLECommand.CommandText = "insert into mytable" & t & " values(""" & t & """, " & t & ")" OLECommand.ExecuteNonQuery() OLECommand.Connection.Close() Catch ex As Exception MsgBox(ex.Message) End Try End If End With
End Sub
Create a table works. However making a file Always fails. Can anyone gives me idaes? I've tryed installing the 32 and 64 bit version of Microsoft Access Database Engine 2010 Redistributable I'm working on a W10 machine 64bit
You are missing quite a bit of logic in creating the database. The sequence of events should be:
string connectionString = string.Format("Provider=Microsoft.ACE.OLEDB.12.0;Data Source={0}", tbFilename.Text);
// Create the catalog
ADOX.Catalog cat = new ADOX.Catalog();
cat.Create(connectionString);// create a new table
ADOX.Table adoxTable = new ADOX.Table();
adoxTable.Name =// add columns to the table
ADOX.DataTypeEnum dbType = adoxTable.Columns.Append(, dbType);// add the Table to the catalog
cat.Tables.Append(adoxTable);// Close the database - thus creating the physical file
ADODB.Connection con = cat.ActiveConnection as ADODB.Connection;
con.Close(); -
Hi, I try to create an access 2007 or higher file. I wrote this testcode just an simple form with 2 buttons.
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles btnMake.Click
Dim dlg As New SaveFileDialogWith dlg .Filter = "Access(\*.accdb)|\*.accdb" If .ShowDialog = DialogResult.OK Then Dim cat As New ADOX.Catalog() Try cat.Create("Provider=Microsoft.ACE.OLEDB.102.0;Data Source=" & .FileName & ";Persist Security Info=True") 'cat.Create("Driver={Microsoft Access Driver (\*.mdb, \*.accdb)};DBQ=" & .FileName) Catch ex1 As Exception MsgBox(ex1.Message) If MsgBox("Is Microsoft Access Database Engine 2010 Redistributable installed?", vbQuestion Or MsgBoxStyle.YesNo) = MsgBoxResult.No Then Try Process.Start("https://www.microsoft.com/en-us/download/details.aspx?id=13255") MsgBox("Do it :)", MsgBoxStyle.SystemModal) Catch ex2 As Exception End Try End If Finally cat = Nothing End Try End If End With
End Sub
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles btnOpen.Click
Dim dlg As New OpenFileDialogWith dlg .Filter = "Access(\*.accdb)|\*.accdb" If .ShowDialog = DialogResult.OK Then Dim OLEConnection As New OleDb.OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & .FileName & ";Persist Security Info=True") OLEConnection.Open() Dim OLECommand As New OleDb.OleDbCommand("", OLEConnection) ' Before this line you can create a string that holds your build for the table structure Randomize() Dim t As Int64 = Int(Rnd() \* 100000) Try OLECommand.CommandText = "CREATE TABLE mytable" & t & " (field1 CHAR,field2 NUMBER)" OLECommand.ExecuteNonQuery() MsgBox("Table " & t & " maded") OLECommand.CommandText = "insert into mytable" & t & " values(""" & t & """, " & t & ")" OLECommand.ExecuteNonQuery() OLECommand.Connection.Close() Catch ex As Exception MsgBox(ex.Message) End Try End If End With
End Sub
Create a table works. However making a file Always fails. Can anyone gives me idaes? I've tryed installing the 32 and 64 bit version of Microsoft Access Database Engine 2010 Redistributable I'm working on a W10 machine 64bit
Check this: [Create Microsoft Access Database Programmatically using VB.NET](https://www.codeproject.com/Tips/813055/Create-Microsoft-Access-Database-Programmatically)
-
You are missing quite a bit of logic in creating the database. The sequence of events should be:
string connectionString = string.Format("Provider=Microsoft.ACE.OLEDB.12.0;Data Source={0}", tbFilename.Text);
// Create the catalog
ADOX.Catalog cat = new ADOX.Catalog();
cat.Create(connectionString);// create a new table
ADOX.Table adoxTable = new ADOX.Table();
adoxTable.Name =// add columns to the table
ADOX.DataTypeEnum dbType = adoxTable.Columns.Append(, dbType);// add the Table to the catalog
cat.Tables.Append(adoxTable);// Close the database - thus creating the physical file
ADODB.Connection con = cat.ActiveConnection as ADODB.Connection;
con.Close();