Results 1 to 16 of 16

Thread: [RESOLVED] Creats an access database

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Jan 2005
    Posts
    118

    Resolved [RESOLVED] Creats an access database

    Hi All,
    I have recently downlodaed some code that displays images which i have found very useful. In the sample app that i downloaded there was a form that let you create access databases. I clicked it and hey presto it created a database! only problem is I have searched through all the code but I cant work out how it does it????. I have included the code below that starts when you click the make database button.
    If anyone could help me out I will be over the moon....
    VB Code:
    1. Private Sub LaVolpeButton3_Click()
    2.     With frmMain.CommonDialog1
    3.         .DialogTitle = "Create a very new database"
    4.         .Filter = "Archive Design Database |*.mdb"
    5.         .Flags = cdlOFNExplorer Or cdlOFNHideReadOnly
    6.         .FileName = ""
    7.         .ShowSave
    8.     End With
    9.    
    10.     If frmMain.CommonDialog1.FileName = "" Then Exit Sub
    11.     'filecopy copies a file -which file?
    12.     FileCopy App.path & "\shell", frmMain.CommonDialog1.FileName
    13.  
    14.     If TestDb(frmMain.CommonDialog1.FileName) = True Then
    15.         srcDB = frmMain.CommonDialog1.FileName
    16.         lblDatabase.Caption = srcDB
    17.         frmMain.loadcat
    18.         frmMain.ListView1.ListItems.Clear
    19.     End If
    20.    
    21. End Sub

    Thanks
    Franki
    Last edited by Hack; Jun 13th, 2006 at 10:51 AM. Reason: Added [vbcode][/vbcode] tags for more clarity.

  2. #2
    Fanatic Member robbedaya's Avatar
    Join Date
    Jul 2002
    Location
    Belgium
    Posts
    872

    Re: Creats an access database

    I think it doesn't create a database.
    I think it just copy's a file called "Shell" (probably an empty database) to the location specified.

  3. #3
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Creats an access database

    Quote Originally Posted by robbedaya
    I think it doesn't create a database.
    I think it just copy's a file called "Shell" (probably an empty database) to the location specified.
    I think you are right.

    Is there a Shell.mdb with this download?

  4. #4

    Thread Starter
    Lively Member
    Join Date
    Jan 2005
    Posts
    118

    Re: Creats an access database

    There is a shell file with the download but it does not show the file extension. It will not open up with access but it does open using the visual data manager, and yes it does appear to be an empty mdb file. This is great because i can now make changes to the database and then save it again as an empty database.
    Thanks for all your input.
    Franki

  5. #5

    Thread Starter
    Lively Member
    Join Date
    Jan 2005
    Posts
    118

    Re: Creats an access database

    Just a quick one regarding table relationships. In the Visual Data Manager there doesnt seem to be a utility for joining tables together. anyone know how to do it using Vis? (Not access)

  6. #6
    PowerPoster
    Join Date
    May 2006
    Posts
    2,988

    Re: Creats an access database

    Dont Know about that .. this is creating a database ..
    (Ref to Microsoft ADO Ext. 2.8 For DDL and Security)
    (also see attachment for example project)

    VB Code:
    1. Dim cat As ADOX.Catalog
    2.     Dim tblNew As ADOX.Table
    3.     Dim idx As ADOX.Index
    4.     Set cat = New ADOX.Catalog
    5.     '// CREATE DATABASE
    6.     cat.Create "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\myfile.mdb;" & _
    7.                 "Jet OLEDB:Database Password=mypass; Jet OLEDB:Encrypt Database=True;"
    8.     Set tblNew = New ADOX.Table
    9.     '// CREATE TABLE
    10.     With tblNew
    11.         .Name = "Table1"
    12.         .ParentCatalog = cat
    13.         .Columns.Append "Table1_Id", adInteger                      ' NUMBER FIELD
    14.         .Columns("Table1_Id").Properties("Autoincrement") = True  
    15.         .Columns("Table1_Id").Properties("Increment") = CLng(1)
    16.         .Columns("Table1_Id").Properties("Seed") = CLng(1)
    17.         .Columns.Append "Table1_Field1", adVarWChar, 255            ' TEXT FIELD
    18.         .Columns.Append "Table1_Field2", adVarWChar, 255            ' TEXT FIELD
    19.         .Columns.Append "Table1_Field3", adInteger                  ' NUMBER FIELD
    20.     End With
    21.     cat.Tables.Append tblNew
    22.     Set idx = New ADOX.Index
    23.     '// SET PRIMARY KEY
    24.     With idx
    25.         .Name = "PrimaryKey"
    26.         .Columns.Append "Table1_Id"
    27.         .PrimaryKey = True
    28.         .Unique = True
    29.     End With
    30.     tblNew.Indexes.Append idx
    31.     Set idx = Nothing
    32.     Set cat = Nothing
    Last edited by RobDog888; Sep 13th, 2006 at 11:36 PM. Reason: disabled smilies in post

  7. #7

    Thread Starter
    Lively Member
    Join Date
    Jan 2005
    Posts
    118

    Re: Creats an access database

    Neat, I'll have a mess around with that.

  8. #8
    PowerPoster
    Join Date
    May 2006
    Posts
    2,988

    Re: Creats an access database

    and just for kicks you can add this to lock the database .. changes the headers so access wont open it .. and then you can also name it anything you want .. just something extra to throw the hackers off .. called in the open and close of the database objects .. i just pulled this out of an existing program i wrote so didnt check it for errors .. (someone else wrote the original "lock")

    VB Code:
    1. Public Enum LockDatabase
    2.    LockData = 1
    3.    UnlockData = 2
    4. End Enum
    5.  
    6. '// OPEN DATABASE CONNECTION
    7. 'Public Sub Open_Database()
    8. '    Database_UnLock
    9. '    Set objConn = CreateObject("ADODB.Connection")
    10. '    objConn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & _
    11. '    App.Path & "\myfile.dll"
    12. 'End Sub
    13.  
    14. '// CLOSE DATABASE CONNECTION
    15. ' Public Sub Close_Database()
    16. '    If Not objConn Is Nothing Then
    17. '        If objConn.State = adStateOpen Then objConn.Close
    18. '    End If
    19. '    Set objConn = Nothing
    20. '    Database_Lock
    21. 'End Sub
    22.  
    23. '// LOCK DATABASE
    24. Public Sub Database_Lock()
    25.     Lock_Database App.Path & "\myfile.dll", 1
    26. End Sub
    27.  
    28. '// PUBLIC SUB ROUTINE: UNLOCK DATABASE
    29. Public Sub Database_UnLock()
    30.     Lock_Database App.Path & "\myfile.dll", 2
    31. End Sub
    32.  
    33. '// LOCK DATABASE PROCESS
    34. Public Sub Lock_Database(sPath As String, iAction As LockDatabase)
    35.    
    36.     Dim hGet        As String
    37.     Dim iFreeFile   As Integer
    38.     Dim iLoop       As Long
    39.     Dim lLoc        As Long
    40.     Dim sString
    41.     Dim lLoop
    42.    
    43.     'If DoesFileExist(App.Path & "\myfile.dll") = True Then
    44.    
    45.         hGet = vbNullString
    46.         iFreeFile = FreeFile()
    47.         Open sPath For Binary As #iFreeFile
    48.         lLoc = 1
    49.         Select Case iAction
    50.             Case 1
    51.                 sString = cmdEnc(strEncrKey)
    52.                 For lLoop = 5 To 19
    53.                     Put #iFreeFile, lLoop, Mid$(sString, lLoop - 4, 1)
    54.                 Next lLoop
    55.             Case 2
    56.                 sString = cmdEnc(strEncrKey)
    57.                 For lLoop = 5 To 19
    58.                     hGet = hGet & Mid$(sString, lLoop - 4, 1)
    59.                 Next lLoop
    60.                 lLoc = 1
    61.            
    62.                 If cmdDec(hGet) = strEncrKey Then
    63.                     sString = "Standard Jet DB"
    64.                     For lLoop = 5 To 19
    65.                         Put #iFreeFile, lLoop, Mid$(sString, lLoop - 4, 1)
    66.                     Next lLoop
    67.                 End If
    68.         End Select
    69.         Close #iFreeFile
    70.     'End If
    71.        
    72. End Sub
    73.  
    74. '// DOES FILE EXIST - FSO
    75. Public Function DoesFileExist(ByVal Filename As String) As Boolean
    76.     On Error Resume Next
    77.     Dim fso
    78.     Set fso = CreateObject("Scripting.FileSystemObject")
    79.     If (fso.FileExists(Filename)) Then
    80.         DoesFileExist = True
    81.     Else
    82.         DoesFileExist = False
    83.     End If
    84.     Set fso = Nothing
    85. End Function
    Last edited by rory; Jun 14th, 2006 at 04:09 AM.

  9. #9
    PowerPoster Simply Me's Avatar
    Join Date
    Aug 2003
    Posts
    2,748

    Re: Creats an access database

    rory, your code is nice but one thing, I tried to download you create database and run it. Now, I tried to delete the create database and it cannot be deleted why?
    To give is always to be NOBLE...
    To received is always to be BLESSED....
    Each day strive to be NOBLE
    Each day strive to be BLESSED

    If this post has helped you. Please take time to rate it.

    >=|+|=< Simply Me >=|+|=<

    ----------------------------------------
    Connection Strings | Number Only in Textbox | Splash Screen with Progress Bar | Printing to 1/2 of perforated bond paper |
    Freeze 2005 DataGridView Column

  10. #10
    PowerPoster
    Join Date
    May 2006
    Posts
    2,988

    Re: Creats an access database

    Dunno .. . I can delete the Database file without a problem .. what error are you getting..?

  11. #11
    PowerPoster Simply Me's Avatar
    Join Date
    Aug 2003
    Posts
    2,748

    Re: Creats an access database

    ooppss. Im sorry rory, it not your code the causes it. its my computer for some reason it does not allow me.

    Anyway, how do I implement the lock and unlock database?
    To give is always to be NOBLE...
    To received is always to be BLESSED....
    Each day strive to be NOBLE
    Each day strive to be BLESSED

    If this post has helped you. Please take time to rate it.

    >=|+|=< Simply Me >=|+|=<

    ----------------------------------------
    Connection Strings | Number Only in Textbox | Splash Screen with Progress Bar | Printing to 1/2 of perforated bond paper |
    Freeze 2005 DataGridView Column

  12. #12
    PowerPoster
    Join Date
    May 2006
    Posts
    2,988

    Re: Creats an access database

    same as i put above, you unlock the database before you open it .. and lock it when you close it ... just change the name of the DB to your own ..

    I just included the Open and Close Database Subs as an example .. you can use your own ..

    The DoesFileExist check can be changed to your own also, its just what I used.

    [edit] i commented out the stuff you can change to your own ..
    Last edited by rory; Jun 14th, 2006 at 04:09 AM.

  13. #13
    PowerPoster Simply Me's Avatar
    Join Date
    Aug 2003
    Posts
    2,748

    Re: Creats an access database

    I just pasted you code below the code in the zip file and it seems not working. Also the Function DoesFileExist is not checking if it exist. Everytime i clicked the button it says in my immediate window Database created.
    To give is always to be NOBLE...
    To received is always to be BLESSED....
    Each day strive to be NOBLE
    Each day strive to be BLESSED

    If this post has helped you. Please take time to rate it.

    >=|+|=< Simply Me >=|+|=<

    ----------------------------------------
    Connection Strings | Number Only in Textbox | Splash Screen with Progress Bar | Printing to 1/2 of perforated bond paper |
    Freeze 2005 DataGridView Column

  14. #14
    PowerPoster
    Join Date
    May 2006
    Posts
    2,988

    Re: Creats an access database

    Ok yeah. its not entierly related .. it takes a little more than that . .. ill post something that combines the 2 of them ..

  15. #15
    PowerPoster Simply Me's Avatar
    Join Date
    Aug 2003
    Posts
    2,748

    Re: Creats an access database

    will the creation of database take care also of the relationships?
    To give is always to be NOBLE...
    To received is always to be BLESSED....
    Each day strive to be NOBLE
    Each day strive to be BLESSED

    If this post has helped you. Please take time to rate it.

    >=|+|=< Simply Me >=|+|=<

    ----------------------------------------
    Connection Strings | Number Only in Textbox | Splash Screen with Progress Bar | Printing to 1/2 of perforated bond paper |
    Freeze 2005 DataGridView Column

  16. #16
    PowerPoster
    Join Date
    May 2006
    Posts
    2,988

    Re: Creats an access database

    Not in the example i posted, you will need to take it further yourself on that part .. sorry :-)

    Here are 2 integrated examples .. both use the lock and unlock subs .. and both use a password when creating the database ..

    one of them also goes further using a well known open source VB encryption on the password .. locks yah right out though so you would need to do all Database related stuff within your code .. or add the encrypted pass to text box and copy it .. then use Ctrl-V to paste it into a Database password box ..
    Last edited by rory; Jun 14th, 2006 at 05:09 AM.

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