Results 1 to 4 of 4
  1. #1
    3 Star Lounger
    Join Date
    Jan 2001
    Location
    Serbia and Montenegro (Yugoslavia)
    Posts
    342
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Determine if DSN Exists

    Does anyone know if there is a way to programmatically determine if a DSN currently exists (registered) in the ODBC manager?

  2. #2
    2 Star Lounger
    Join Date
    Jan 2001
    Location
    Winnipeg, Canada
    Posts
    109
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Determine if DSN Exists

    Hi Mike,

    There are always interesting challenges in this place and yours was one of those.

    My dsn files are located in C:WindowsODBCData Sources, so I thought there should be a way to determine if a certain dsn was available by writing a function for it.

    I looked around in Help and found some info in FileSearch object.

    From the 2 available example code snippets I made the following function (I remmed out some of the stuff I didn't
    want to see, but left it in so you can check it against the Help )

    Public Function FileExists(myFileName As String, myPath As String) As Boolean
    Dim i As Integer

    With Application.FileSearch
    .NewSearch
    .LookIn = myPath
    .SearchSubFolders = True
    .FileName = myFileName
    .MatchTextExactly = True
    '.FileType = msoFileTypeAllFiles
    End With

    With Application.FileSearch
    If .Execute() > 0 Then
    FileExists = True
    'MsgBox "There were " & .FoundFiles.count & _
    ' " file(s) found."

    'For i = 1 To .FoundFiles.count
    ' MsgBox .FoundFiles(i)
    'Next i
    Else
    'MsgBox "There were no files found."
    FileExists = False
    End If
    End With
    End Function

    I ran the following test:
    ? FileExists("CDrafts.dsn","C:WindowsODBCData Sources")
    and it returned True. <img src=/S/smile.gif border=0 alt=smile width=15 height=15>

    Is this what you wanted?

  3. #3
    3 Star Lounger
    Join Date
    Jan 2001
    Location
    Serbia and Montenegro (Yugoslavia)
    Posts
    342
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Determine if DSN Exists

    Thanks, Ken..I'll have to play with this code. I am using NT so I don't have an ODBC sub directory, but it should just take a little searching.

    Thanks again,
    Mike

  4. #4
    Plutonium Lounger
    Join Date
    Dec 2000
    Location
    Sacramento, California, USA
    Posts
    16,775
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Determine if DSN Exists

    I run NT and I have an ODBC directory under C:Program FilesCommon FilesODBC.
    Charlotte

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •