LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 23
Default If ODBC DSN connection fails

I have an Excel workbook with multiple sheets, each with its own Microsoft
Query. I have created a User Form to accept variables UsrID & Psw, which I
then plug into the connection string for each query within a For Each . . .
Next loop, as follows:

For Each Sht in .Sheets(Array(etc. . . ))
Sht.Activate
Range("A1").Select
With .Selection.QueryTable
.Connection = "ODBC;DSN=servername;UID=" _
& UsrID _
& ";Pwd=" _
& Psw _
& ";"
.Refresh.BackgroundQuery:=False
End With
Next Sht

The problem is, if the UsrID/Psw combination is not valid, each connection
attempt forces prompts for data source, ID & password.

Is there a way to validate UsrID & Psw before reaching this For Each . . .
Next loop, so that, if they are not valid, I will stay within a Do . . .
Until loop & reshow the User Form for re-entry?

I tried .DisplayAlerts = False before the .Refresh to see if there is an
error to trap.
It returns Run-time error '1004': General ODBC Error.
Is it sufficient to trap this error on the first refresh & have the User
Form accessed conditionally within this loop?
It seems too non-specific an error to assume this is the only reason it will
be thrown on the refresh???
--
Will
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
SQL ODBC Connection Bythsx-Addagio[_2_] Excel Programming 1 February 24th 09 08:51 PM
SQL ODBC Connection rich19k83 Excel Programming 0 December 12th 08 11:27 AM
ODBC Connection Kezzemil Excel Programming 0 October 6th 06 09:15 AM
ODBC Connection Adrian T[_4_] Excel Programming 4 January 25th 05 08:55 PM
ODBC connection by udl Dorothy[_4_] Excel Programming 1 January 8th 04 05:32 PM


All times are GMT +1. The time now is 09:27 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"