CRIANDO ARQUIVO DO ACESS VIA CODIGO

LEOPORFIRIO 10/10/2013 21:06:55
#429871
Olá, galera estou precisando de ajuda para criar um arquivo do acess pelo vb via codigo ,seria feito com create object ?
MADMAX 11/10/2013 12:17:27
#429902
LEOPORFIRIO você quer criar um DB no acess e isso ??? segue um exemplo de como fazer ...

Option Explicit
Sub CreateAccessDatabase(sDatabaseToCreate)
Dim catNewDB As ADOX.Catalog
Set catNewDB = New ADOX.Catalog
catNewDB.Create [Ô]Provider=Microsoft.Jet.OLEDB.4.0;[Ô] & _
[Ô]Data Source=[Ô] & sDatabaseToCreate & _
[Ô];Jet OLEDB:Engine Type=5;[Ô]
[ô] Engine Type=5 = Access 2000 Database
[ô] Engine Type=4 = Access 97 Database
Set catNewDB = Nothing
End Sub

Sub CreateAccessTable(sDatabaseToCreate)

Dim catDB As ADOX.Catalog
Dim tblNew As ADOX.Table
Set catDB = New ADOX.Catalog

[ô] Open the catalog
catDB.ActiveConnection = [Ô]Provider=Microsoft.Jet.OLEDB.4.0;[Ô] & _
[Ô]Data Source=[Ô] & sDatabaseToCreate

[ô] Create new Table
Set tblNew = New ADOX.Table
tblNew.Name = [Ô]Contacts[Ô]

[ô] First Create an Autonumber column, called ID.
[ô] This is just for demonstration purposes.
[ô] We could have done this below with all the other
[ô] columns as well
Dim col As ADOX.Column
Set col = New ADOX.Column

With col
.ParentCatalog = catDB
.Type = adInteger [ô] adText does not exist
.Name = [Ô]ID[Ô]
.Properties([Ô]Autoincrement[Ô]) = True
.Properties([Ô]Description[Ô]) = [Ô]I am the Description [Ô] & _
[Ô]for the column[Ô]
End With
tblNew.Columns.Append col

[ô] Now add the rest of the columns
With tblNew
[ô] Create fields and append them to the
[ô] Columns collection of the new Table object.
With .Columns
.Append [Ô]NumberColumn[Ô], adInteger
.Append [Ô]FirstName[Ô], adVarWChar
.Append [Ô]LastName[Ô], adVarWChar
.Append [Ô]Phone[Ô], adVarWChar
.Append [Ô]Notes[Ô], adLongVarWChar
End With

Dim adColNullable [ô] Is not defined in adovbs.inc,
[ô] so we need to define it here.
[ô] The other option is adColFixed with a value of 1
adColNullable = 2
With .Columns([Ô]FirstName[Ô])
.Attributes = adColNullable
End With
End With

[ô] Add the new Table to the Tables collection of the database.
catDB.Tables.Append tblNew
Set col = Nothing
Set tblNew = Nothing
Set catDB = Nothing
End Sub

Private Sub Form_Load()
Dim sDatabaseName As String
sDatabaseName = [Ô]C:\MyNewDatabase.mdb[Ô]
[ô] First call the Create Database method
CreateAccessDatabase sDatabaseName
[ô] Then add a table and columns to this database
CreateAccessTable sDatabaseName
MsgBox [Ô]Database has been created successfully![Ô]
End Sub
LEOPORFIRIO 11/10/2013 12:39:03
#429906
na verdade MADMAX ,é que tenho um sistema que uso esse arquivo como verificação , se algum usuario apagar esse arquivo o sistema fecha , queria criar apenas o arquivo dados_temp para não ocorrer esse erro.
Faça seu login para responder