Results 1 to 4 of 4

Thread: [RESOLVED] Create new File in access 2003 using vb6

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Nov 2013
    Posts
    25

    Resolved [RESOLVED] Create new File in access 2003 using vb6

    hi all
    i have create a text box of New file Name and when i put file name in that box and click on ok button it is created a file of access database in said path with the same name which is type in text box. i am trying some code but it is not created with the name which i type in text box of New file name. so please help me below please find the code of the same.

    Private Sub cmdOk_Click()

    Dim fName As String
    Dim sDatabaseName As String
    fName = txtNew.Text
    sDatabaseName = "e:\TDS Software/Data/Test.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

    Private Sub Form_Load()
    frmMain.Enabled = False

    End Sub

    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 = "DedctrMaster"

    ' 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()

    'End Sub

  2. #2
    PowerPoster SamOscarBrown's Avatar
    Join Date
    Aug 2012
    Location
    NC, USA
    Posts
    9,145

    Re: Create new File in access 2003 using vb6

    change this:
    Code:
    Dim fName As String
    Dim sDatabaseName As String
    fName = txtNew.Text
    sDatabaseName = "e:\TDS Software/Data/Test.mdb"
    to:
    Code:
    Dim sDatabaseName as String
    sDatabaseName = "e:\TDS Software/Data/" & trim(txtNew.text) & ".mdb"

  3. #3
    Frenzied Member
    Join Date
    May 2006
    Location
    some place in the cloud
    Posts
    1,886

    Re: Create new File in access 2003 using vb6

    Also, change / to \
    JG


    ... If your problem is fixed don't forget to mark your threads as resolved using the Thread Tools menu ...

  4. #4

    Thread Starter
    Junior Member
    Join Date
    Nov 2013
    Posts
    25

    Re: Create new File in access 2003 using vb6

    Thank you all of you this problem is solved

    but there is one more problem that i have make one project which is used by Tax practitioner. in this software they are creating a file of their client and calculated a tax and submitting to department. As you all of help to me for creating a file in access database now my problem is that if i create a one file which name is "Kalpesh Shah" and i have make some entries in that and saved it to in database then when i need to see the same file again through my project and it shows me all records which is saved in database in my project form. For that i have think that i should use my own Extension to that file which is created through this programmed(project) so when he needs to open a file which is already create he press on OPEN menu where he founds Browser and he selected his deliverable file from that browser and press ok and that time the same file is open in my project with its database.........................i am very poor in vb6 so here i am putting my concept but i can't think that from where i have to start the code for this kind of concept. so please help me or guide me how can i complete my concept in my project.................. Thanks once again thank you very much for reading my full concept and please help me.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width