Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Old DAO code into ADO conversion problem

Status
Not open for further replies.

LittleSmudge

Programmer
Mar 18, 2002
2,848
GB
I have some code in DAO that creates a new database in the current db'd folder that is straight out of the Access97 help manual

Code:
Sub CreateDatabaseX()

    Dim wrkDefault As Workspace
    Dim dbsNew As DATABASE
    Dim prpLoop As Property

    ' Get default Workspace.
    Set wrkDefault = DBEngine.Workspaces(0)

    ' Make sure there isn't already a file with the name of 
    ' the new database.
    If Dir(&quot;Activity.mdb&quot;) <> &quot;&quot; Then Kill &quot;Activity.mdb&quot;

    ' Create a new database with the specified collating order.
    Set dbsNew = wrkDefault.CreateDatabase(&quot;Activity.mdb&quot;, _
        dbLangGeneral)

    dbsNew.Close

End Sub

However, I'm now working on a A2000 implementation using ADO and I do NOT want to have to reference the DAO libraries on all the users machines that this will run on.

ADO does not recognise Workspace or Database as types.


What is the ADO equivalent of this code ?



G LS
 
Thanks cmmrfrds, thats a useful link.

It didn't directly answer the question but it lead on to other links that allows me to work it out ( and answer a few more issues to boot.

It seems I'm going to have to change library references afterall becuase to do what I want I will need &quot;ADO 2.5 ADOX for Security&quot; which is not standard on the user's machines either.

I'll post a separate query about using code to test for library references and install them if not already there.


Thanks,

G LS
 
I was curuious about setting the reference library from vba code. Here is code to check and set. You can investigate how to remove library.

Function ReferenceFromFile(strFileName As String) As Boolean
Dim ref As Reference

On Error GoTo Error_ReferenceFromFile
Set ref = References.AddFromFile(strFileName)
ReferenceFromFile = True

Exit_ReferenceFromFile:
Exit Function

Error_ReferenceFromFile:
MsgBox Err & &quot;: &quot; & Err.description
ReferenceFromFile = False
Resume Exit_ReferenceFromFile
End Function

Function CreateReference()
If ReferenceFromFile(&quot;C:\Program Files\Common Files\SYSTEM\ADO\msadox.dll&quot;) = True Then
MsgBox &quot;Reference set successfully.&quot;
Else
MsgBox &quot;Reference not set successfully.&quot;
End If
End Function

 
Thanks again cmmrfrds,

This, combined with the code supplied by FP in thread705-354999 gives me all I need.
The code in the link shows how to extract the Full Path Name of the Reference. So I'll be able to work it out from here.


G LS
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top