|
-
May 9th, 2007, 06:53 AM
#1
Thread Starter
Fanatic Member
Creating new datalinks - No place to put datalink filename [Solved]
Hey guys, I found it's pretty simple to create new datalinks dynamically at runtime.
Code:
Dim dl As New Datalinks
dl.PromptNew
I know what's causing my problem, I just don't have a solution. That code brings up a datalink creation menu. I make it use the Jet 4.0 database, link it to my mdb file, but I can't give it a filename, hence the file doesn't appear in the folder, and as a result, of course, I can't define the ConnectionString in my ADO data control because I can't give the new datalink a name.
Anyone know how to solve this problem? Is this by design, and if so, how does the ADO data control know how to define the ConnectionString?
Last edited by hothead; May 9th, 2007 at 08:02 AM.
-
May 9th, 2007, 08:02 AM
#2
Thread Starter
Fanatic Member
Re: Creating new datalinks - No place to put datalink filename
I found it out myself. It's by design, and it's a good way to create a datalink dynamically without placing any extra files on your harddrive. Here's my entire code, in case anyone else runs into the same problem, or needs to create their own databases. NOTE: The CreateTable part doesn't work yet, I'm still researching the steps involved. It will go through fine, but you won't see the table when you physically open Access.
Code:
Private Sub RecordControls_Click(Index As Integer)
Select Case Index
Case 0
Dim WkSpc As DAO.Workspace
Dim dl As DataLinks
Dim conn As Connection
On Error GoTo ErrorHandler
If MasterControl.Text = "" Then
MsgBox "You must specify a header in which to put the data.", vbInformation, App.Title
Exit Sub
End If
Set WkSpc = Workspaces(0)
WkSpc.CreateDatabase App.Path & "\Databases\" & MasterControl.Text & ".mdb", dbLangGeneral
Set dl = New DataLinks
Set conn = dl.PromptNew
Set rs = New Recordset
DAOConnection.RecordSource = "CREATE TABLE " & MasterControl.Text & " (Test CHAR(250))"
DatabaseConnection.ConnectionString = conn.ConnectionString
Set WkSpc = Nothing
Set dl = Nothing
Set conn = Nothing
Set rs = Nothing
Exit Sub
End Select
ErrorHandler:
MsgBox Err.Description, vbCritical, "Database Error"
Exit Sub
End Sub
NOTE: I used the DAO control because in my search to find out how to do this, I found that the Microsoft Jet Database Engine does not support creating tables with non-MSJD-standard controls, like the ADO data control. I've seen it done in .NET with ADOX though, but that point is moot because it doesn't help here.
Last edited by hothead; May 9th, 2007 at 08:24 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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|