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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Can I read other registry area by VBA?

Status
Not open for further replies.

snoooopy

Programmer
Aug 13, 2002
9
US

Dear All:

Did anybody know how to read the registry except "VB and VBA Program Settings". I want read ODBC user DSN information.

My point is what kind of database customer using in the runtime. So I can write 2 DIFFERENT statements to link Access or SQL Server by DAO.






 
Heres one way to look up and read the ODBC

Private Declare Function SQLDataSources Lib "ODBC32.DLL" (ByVal henv As Long, ByVal fDirection As Integer, ByVal szDSN As String, ByVal cbDSNMax As Integer, pcbDSN As Integer, ByVal szDescription As String, ByVal cbDescriptionMax As Integer, pcbDescription As Integer) As Integer
Private Declare Function SQLAllocEnv Lib "ODBC32.DLL" (env As Long) As Integer

Sub Sample()
FindDSN_Driver "CDLibrary"
End Sub


Public Function FindDSN_Driver(DB_DSN As String)
Dim dSource As Integer
Dim strDSN As String * 1024
Dim strDRV As String * 1024
Dim szDSN As Integer
Dim szDRV As Integer
Dim hdlENV As Long
On Error Resume Next
If SQLAllocEnv(hdlENV) <> -1 Then
Do Until dSource <> 0
dSource = SQLDataSources(hdlENV, 1, strDSN, 1024, szDSN, strDRV, 1024, szDRV)
If Left$(strDSN, szDSN) = DB_DSN Then
MsgBox Left$(strDRV, szDRV)
End If
Loop
End If
End Function
 
I reference the ODBC but I indeed cannot find those function in your program, such as SQLDataSources() and SQLAllocENV().

But, I resolve my problem by using .OpenConnection() statement. Because .OpenDatabase() change the engine automatically. It always believes that Access is a ISAM DB and must use Jet. So I use .OpenConnection()
 
By the way. Did any boys and gals know my question itself, read ans write other registry area?

In VBA, we just can use SaveSetting(), GetSetting() to visit the HKEY_CURRENT_USER/Software/VB and VBA Program Settings/...
And such as the RegOpenEx() functions is NOT available in VBA.

So what can I do?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top