Results 1 to 13 of 13

Thread: [RESOLVED] creating new mdb file?

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Jun 2004
    Location
    cainta
    Posts
    80

    Resolved [RESOLVED] creating new mdb file?

    Hi all,

    my objective is to open a csv file and save it to new mdb file at "c:\my_file" directory.

    how to create new mdb file in vb6 code? the file name of the mdb will be base on csv file name.

    many thanks!

  2. #2
    PowerPoster RhinoBull's Avatar
    Join Date
    Mar 2004
    Location
    New Amsterdam
    Posts
    24,132

    Re: creating new mdb file?

    A new database for each new file? Sounds very unreasonable.
    Instead, if csv files will always have the same layout then you can design a table and load it with new data.
    For each new load you will need to assign so unique id or at least date it was loaded.
    Whether you design one table or multple (they will have to relate somehow) is up to you.

  3. #3

  4. #4

    Thread Starter
    Lively Member
    Join Date
    Jun 2004
    Location
    cainta
    Posts
    80

    Re: creating new mdb file?

    Quote Originally Posted by MartinLiss View Post
    Why did you start this thread when you marked your other similar thread as resolved?
    Hi Martinliss,

    I think my previous thread it solved only the parsing of the txt file then add to existing mdb. my problem now is how will i create new mdb file? i want to make it automated in creating this mdb file.

  5. #5
    Discovering Life Siddharth Rout's Avatar
    Join Date
    Feb 2005
    Location
    Mumbai, India
    Posts
    12,001

    Re: creating new mdb file?

    Here is a very basic way to create an MDB file... First please set a reference to Microsoft DAO 3.6 Object Library

    Remember this is a just a basic example of how to create an MDB. Please amend it as per your requirements...

    vb Code:
    1. '~~> Set reference to Microsoft DAO 3.6 Object Library
    2.  
    3. Private Sub Command1_Click()
    4.     '~~> Replace this with your path and filename
    5.     CreateDB "c:\my_file\Mydatabase.mdb"
    6. End Sub
    7. Sub CreateDB(mdbPath As String)
    8.     Dim tdefMDB As TableDef, txtFieldone As Field, txtFieldtwo As Field
    9.     Dim dateFieldone As Field, memoFieldone As Field, dbDatabase As Database
    10.     Dim sNewDBPathAndName As String
    11.    
    12.     sNewDBPathAndName = mdbPath
    13.     Set dbDatabase = CreateDatabase(sNewDBPathAndName, dbLangGeneral, dbEncrypt)
    14.  
    15.     '~~> Create new TableDef (I am creating a table Table1)
    16.     Set tdefMDB = dbDatabase.CreateTableDef("Table1")
    17.  
    18.     '~~> Add fields to MDB
    19.     '~~> for eample I am creating two text fields, 1 date field and
    20.     '~~> 1 memo field. Amend as applicable
    21.     Set txtFieldone = tdefMDB.CreateField("txtField1", dbText, 20)
    22.     Set txtFieldtwo = tdefMDB.CreateField("txtField2", dbText, 20)
    23.     Set dateFieldone = tdefMDB.CreateField("dateField1", dbDate)
    24.     Set memoFieldone = tdefMDB.CreateField("memoField1", dbMemo)
    25.    
    26.     '~~> Append the field objects to the TableDef
    27.     tdefMDB.Fields.Append txtFieldone
    28.     tdefMDB.Fields.Append txtFieldtwo
    29.     tdefMDB.Fields.Append dateFieldone
    30.     tdefMDB.Fields.Append memoFieldone
    31.  
    32.     '~~> Save TableDef definition by appending it to TableDefs collection.
    33.     dbDatabase.TableDefs.Append tdefMDB
    34.    
    35.     '~~> Inform user.
    36.     MsgBox "New .MDB Created - '" & sNewDBPathAndName & "'", vbInformation
    37. End Sub
    A good exercise for the Heart is to bend down and help another up...
    Please Mark your Thread "Resolved", if the query is solved


    MyGear:
    ★ CPU ★ Ryzen 5 5800X
    ★ GPU ★ NVIDIA GeForce RTX 3080 TI Founder Edition
    ★ RAM ★ G. Skill Trident Z RGB 32GB 3600MHz
    ★ MB ★ ASUS TUF GAMING X570 (WI-FI) ATX Gaming
    ★ Storage ★ SSD SB-ROCKET-1TB + SEAGATE 2TB Barracuda IHD
    ★ Cooling ★ NOCTUA NH-D15 CHROMAX BLACK 140mm + 10 of Noctua NF-F12 PWM
    ★ PSU ★ ANTEC HCG-1000-EXTREME 1000 Watt 80 Plus Gold Fully Modular PSU
    ★ Case ★ LIAN LI PC-O11 DYNAMIC XL ROG (BLACK) (G99.O11DXL-X)
    ★ Monitor ★ LG Ultragear 27" 240Hz Gaming Monitor
    ★ Keyboard ★ TVS Electronics Gold Keyboard
    ★ Mouse ★ Logitech G502 Hero

  6. #6
    Frenzied Member wpearsall's Avatar
    Join Date
    Feb 2002
    Location
    England / UK
    Posts
    1,065

    Re: creating new mdb file?

    Useful Code

    - do you have a list of available options to hand? such as settng primary key? and indexed etc
    Wayne

  7. #7
    Discovering Life Siddharth Rout's Avatar
    Join Date
    Feb 2005
    Location
    Mumbai, India
    Posts
    12,001

    Re: creating new mdb file?

    @Wayne:

    vb Code:
    1. Dim ind As DAO.Index
    2.  
    3. '~~> rest of the code as mentioned above ....
    4. Set ind = tdefMDB.CreateIndex("PrimaryKey")
    A good exercise for the Heart is to bend down and help another up...
    Please Mark your Thread "Resolved", if the query is solved


    MyGear:
    ★ CPU ★ Ryzen 5 5800X
    ★ GPU ★ NVIDIA GeForce RTX 3080 TI Founder Edition
    ★ RAM ★ G. Skill Trident Z RGB 32GB 3600MHz
    ★ MB ★ ASUS TUF GAMING X570 (WI-FI) ATX Gaming
    ★ Storage ★ SSD SB-ROCKET-1TB + SEAGATE 2TB Barracuda IHD
    ★ Cooling ★ NOCTUA NH-D15 CHROMAX BLACK 140mm + 10 of Noctua NF-F12 PWM
    ★ PSU ★ ANTEC HCG-1000-EXTREME 1000 Watt 80 Plus Gold Fully Modular PSU
    ★ Case ★ LIAN LI PC-O11 DYNAMIC XL ROG (BLACK) (G99.O11DXL-X)
    ★ Monitor ★ LG Ultragear 27" 240Hz Gaming Monitor
    ★ Keyboard ★ TVS Electronics Gold Keyboard
    ★ Mouse ★ Logitech G502 Hero

  8. #8

  9. #9
    Discovering Life Siddharth Rout's Avatar
    Join Date
    Feb 2005
    Location
    Mumbai, India
    Posts
    12,001

    Re: creating new mdb file?

    I absolutely agree with Rhino that DAO is outdated and I myself use the ADOX but this is the only scenario where I use DAO probably because I remember this code like the back of my hand and it makes me create the MDB in no time.... Guess I am too lazy now a days...
    A good exercise for the Heart is to bend down and help another up...
    Please Mark your Thread "Resolved", if the query is solved


    MyGear:
    ★ CPU ★ Ryzen 5 5800X
    ★ GPU ★ NVIDIA GeForce RTX 3080 TI Founder Edition
    ★ RAM ★ G. Skill Trident Z RGB 32GB 3600MHz
    ★ MB ★ ASUS TUF GAMING X570 (WI-FI) ATX Gaming
    ★ Storage ★ SSD SB-ROCKET-1TB + SEAGATE 2TB Barracuda IHD
    ★ Cooling ★ NOCTUA NH-D15 CHROMAX BLACK 140mm + 10 of Noctua NF-F12 PWM
    ★ PSU ★ ANTEC HCG-1000-EXTREME 1000 Watt 80 Plus Gold Fully Modular PSU
    ★ Case ★ LIAN LI PC-O11 DYNAMIC XL ROG (BLACK) (G99.O11DXL-X)
    ★ Monitor ★ LG Ultragear 27" 240Hz Gaming Monitor
    ★ Keyboard ★ TVS Electronics Gold Keyboard
    ★ Mouse ★ Logitech G502 Hero

  10. #10
    Frenzied Member wpearsall's Avatar
    Join Date
    Feb 2002
    Location
    England / UK
    Posts
    1,065

    Re: creating new mdb file?

    i just found it useful yesterday because i cant find my office CD and needed to create an MDB [recent format means no office ] - but its so simple i created the DB FASTER then in access, and didnt have to backup the mdb incase my code screwed it... good tool for devel :P - at least i thought so - cheers
    Wayne

  11. #11
    Discovering Life Siddharth Rout's Avatar
    Join Date
    Feb 2005
    Location
    Mumbai, India
    Posts
    12,001

    Re: creating new mdb file?

    Yeah I use it very often... like I mentioned, I am too lazy
    A good exercise for the Heart is to bend down and help another up...
    Please Mark your Thread "Resolved", if the query is solved


    MyGear:
    ★ CPU ★ Ryzen 5 5800X
    ★ GPU ★ NVIDIA GeForce RTX 3080 TI Founder Edition
    ★ RAM ★ G. Skill Trident Z RGB 32GB 3600MHz
    ★ MB ★ ASUS TUF GAMING X570 (WI-FI) ATX Gaming
    ★ Storage ★ SSD SB-ROCKET-1TB + SEAGATE 2TB Barracuda IHD
    ★ Cooling ★ NOCTUA NH-D15 CHROMAX BLACK 140mm + 10 of Noctua NF-F12 PWM
    ★ PSU ★ ANTEC HCG-1000-EXTREME 1000 Watt 80 Plus Gold Fully Modular PSU
    ★ Case ★ LIAN LI PC-O11 DYNAMIC XL ROG (BLACK) (G99.O11DXL-X)
    ★ Monitor ★ LG Ultragear 27" 240Hz Gaming Monitor
    ★ Keyboard ★ TVS Electronics Gold Keyboard
    ★ Mouse ★ Logitech G502 Hero

  12. #12

    Thread Starter
    Lively Member
    Join Date
    Jun 2004
    Location
    cainta
    Posts
    80

    Thumbs up Re: creating new mdb file?

    Koolsid,

    Thank you!

  13. #13
    Discovering Life Siddharth Rout's Avatar
    Join Date
    Feb 2005
    Location
    Mumbai, India
    Posts
    12,001

    Re: creating new mdb file?

    Quote Originally Posted by Chowking View Post
    Koolsid,

    Thank you!
    Glad to be of help
    A good exercise for the Heart is to bend down and help another up...
    Please Mark your Thread "Resolved", if the query is solved


    MyGear:
    ★ CPU ★ Ryzen 5 5800X
    ★ GPU ★ NVIDIA GeForce RTX 3080 TI Founder Edition
    ★ RAM ★ G. Skill Trident Z RGB 32GB 3600MHz
    ★ MB ★ ASUS TUF GAMING X570 (WI-FI) ATX Gaming
    ★ Storage ★ SSD SB-ROCKET-1TB + SEAGATE 2TB Barracuda IHD
    ★ Cooling ★ NOCTUA NH-D15 CHROMAX BLACK 140mm + 10 of Noctua NF-F12 PWM
    ★ PSU ★ ANTEC HCG-1000-EXTREME 1000 Watt 80 Plus Gold Fully Modular PSU
    ★ Case ★ LIAN LI PC-O11 DYNAMIC XL ROG (BLACK) (G99.O11DXL-X)
    ★ Monitor ★ LG Ultragear 27" 240Hz Gaming Monitor
    ★ Keyboard ★ TVS Electronics Gold Keyboard
    ★ Mouse ★ Logitech G502 Hero

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