home *** CD-ROM | disk | FTP | other *** search
/ Tools / WinSN5.0Ver.iso / PVb5.0 / VB / TEMPLATE / FORMS / ODBCLOG.FRM (.txt) < prev    next >
Encoding:
Visual Basic Form  |  1997-02-17  |  8.2 KB  |  259 lines

  1. VERSION 5.00
  2. Begin VB.Form frmODBCLogon 
  3.    BorderStyle     =   3  'Fixed Dialog
  4.    Caption         =   "ODBC 
  5.    ClientHeight    =   3180
  6.    ClientLeft      =   2850
  7.    ClientTop       =   1755
  8.    ClientWidth     =   4470
  9.    ControlBox      =   0   'False
  10.    Icon            =   "odbclog.frx":0000
  11.    LinkTopic       =   "Form1"
  12.    MaxButton       =   0   'False
  13.    MinButton       =   0   'False
  14.    ScaleHeight     =   3180
  15.    ScaleWidth      =   4470
  16.    ShowInTaskbar   =   0   'False
  17.    StartUpPosition =   2  '
  18.    Begin VB.CommandButton cmdCancel 
  19.       Cancel          =   -1  'True
  20.       Caption         =   "
  21.       Height          =   450
  22.       Left            =   2520
  23.       TabIndex        =   13
  24.       Top             =   2655
  25.       Width           =   1440
  26.    End
  27.    Begin VB.CommandButton cmdOK 
  28.       Caption         =   "
  29. (&O)"
  30.       Height          =   450
  31.       Left            =   915
  32.       TabIndex        =   12
  33.       Top             =   2655
  34.       Width           =   1440
  35.    End
  36.    Begin VB.Frame fraStep3 
  37.       Caption         =   "
  38.       Height          =   2415
  39.       Index           =   0
  40.       Left            =   120
  41.       TabIndex        =   14
  42.       Top             =   120
  43.       Width           =   4230
  44.       Begin VB.TextBox txtUID 
  45.          Height          =   300
  46.          Left            =   1365
  47.          TabIndex        =   3
  48.          Top             =   600
  49.          Width           =   2760
  50.       End
  51.       Begin VB.TextBox txtPWD 
  52.          Height          =   300
  53.          Left            =   1365
  54.          TabIndex        =   5
  55.          Top             =   930
  56.          Width           =   2760
  57.       End
  58.       Begin VB.TextBox txtDatabase 
  59.          Height          =   300
  60.          Left            =   1365
  61.          TabIndex        =   7
  62.          Top             =   1260
  63.          Width           =   2760
  64.       End
  65.       Begin VB.ComboBox cboDSNList 
  66.          Height          =   300
  67.          ItemData        =   "odbclog.frx":000C
  68.          Left            =   1365
  69.          List            =   "odbclog.frx":000E
  70.          Sorted          =   -1  'True
  71.          Style           =   2  'Dropdown List
  72.          TabIndex        =   1
  73.          Top             =   240
  74.          Width           =   2760
  75.       End
  76.       Begin VB.TextBox txtServer 
  77.          Enabled         =   0   'False
  78.          Height          =   330
  79.          Left            =   1365
  80.          TabIndex        =   11
  81.          Top             =   1935
  82.          Width           =   2760
  83.       End
  84.       Begin VB.ComboBox cboDrivers 
  85.          Enabled         =   0   'False
  86.          Height          =   300
  87.          Left            =   1365
  88.          Sorted          =   -1  'True
  89.          Style           =   2  'Dropdown List
  90.          TabIndex        =   9
  91.          Top             =   1590
  92.          Width           =   2760
  93.       End
  94.       Begin VB.Label lblStep3 
  95.          AutoSize        =   -1  'True
  96.          Caption         =   "&DSN:"
  97.          Height          =   195
  98.          Index           =   1
  99.          Left            =   135
  100.          TabIndex        =   0
  101.          Top             =   285
  102.          Width           =   390
  103.       End
  104.       Begin VB.Label lblStep3 
  105.          AutoSize        =   -1  'True
  106.          Caption         =   "&UID:"
  107.          Height          =   195
  108.          Index           =   2
  109.          Left            =   135
  110.          TabIndex        =   2
  111.          Top             =   630
  112.          Width           =   330
  113.       End
  114.       Begin VB.Label lblStep3 
  115.          AutoSize        =   -1  'True
  116.          Caption         =   "
  117. (&P):"
  118.          Height          =   180
  119.          Index           =   3
  120.          Left            =   135
  121.          TabIndex        =   4
  122.          Top             =   975
  123.          Width           =   720
  124.       End
  125.       Begin VB.Label lblStep3 
  126.          AutoSize        =   -1  'True
  127.          Caption         =   "
  128. (&B):"
  129.          Height          =   180
  130.          Index           =   4
  131.          Left            =   135
  132.          TabIndex        =   6
  133.          Top             =   1320
  134.          Width           =   900
  135.       End
  136.       Begin VB.Label lblStep3 
  137.          AutoSize        =   -1  'True
  138.          Caption         =   "
  139. (&V):"
  140.          Height          =   180
  141.          Index           =   5
  142.          Left            =   135
  143.          TabIndex        =   8
  144.          Top             =   1665
  145.          Width           =   1080
  146.       End
  147.       Begin VB.Label lblStep3 
  148.          AutoSize        =   -1  'True
  149.          Caption         =   "
  150. (&S):"
  151.          Height          =   180
  152.          Index           =   6
  153.          Left            =   135
  154.          TabIndex        =   10
  155.          Top             =   2010
  156.          Width           =   900
  157.       End
  158.    End
  159. Attribute VB_Name = "frmODBCLogon"
  160. Attribute VB_GlobalNameSpace = False
  161. Attribute VB_Creatable = False
  162. Attribute VB_PredeclaredId = True
  163. Attribute VB_Exposed = False
  164. Option Explicit
  165. Private Declare Function SQLDataSources Lib "ODBC32.DLL" (ByVal henv&, ByVal fDirection%, ByVal szDSN$, ByVal cbDSNMax%, pcbDSN%, ByVal szDescription$, ByVal cbDescriptionMax%, pcbDescription%) As Integer
  166. Private Declare Function SQLAllocEnv% Lib "ODBC32.DLL" (env&)
  167. Const SQL_SUCCESS As Long = 0
  168. Const SQL_FETCH_NEXT As Long = 1
  169. Private Sub cmdCancel_Click()
  170.     Unload Me
  171. End Sub
  172. Private Sub cmdOK_Click()
  173.     Dim sConnect As String
  174.     Dim sDAOConnect As String
  175.     Dim sDSN As String
  176.     If cboDSNList.ListIndex > 0 Then
  177.         sDSN = cboDSNList.Text
  178.     Else
  179.         sConnect = sConnect & "Driver=" & cboDrivers.Text & ";"
  180.         sConnect = sConnect & "Server=" & txtServer.Text & ";"
  181.     End If
  182.     sConnect = sConnect & "UID=" & txtUID.Text & ";"
  183.     sConnect = sConnect & "PWD=" & txtPWD.Text & ";"
  184.     If Len(txtDatabase.Text) > 0 Then
  185.         sConnect = sConnect & "Database=" & txtDatabase.Text & ";"
  186.     End If
  187.     sDAOConnect = "ODBC;DSN=" & sDSN & ";" & sConnect
  188.     MsgBox "
  189.  DAO 
  190. " & vbCrLf & _
  191.     "Set gDatabase = OpenDatabase(vbNullString, 0, 0, sDAOConnect)" & vbCrLf & vbCrLf & _
  192.     "
  193.  RDO 
  194. " & vbCrLf & _
  195.     "Set gRDOConnection = rdoEnvironments(0).OpenConnection(sDSN, rdDriverNoPrompt, 0, sConnect)"
  196.     'Set gDatabase = OpenDatabase(vbNullString, 0, 0, sDAOConnect)
  197.     'Set gRDOConnection = rdoEnvironments(0).OpenConnection(sDSN, rdDriverNoPrompt, 0, sConnect)
  198. End Sub
  199. Private Sub Form_Load()
  200.     GetDSNsAndDrivers
  201. End Sub
  202. Private Sub cboDSNList_Click()
  203.     On Error Resume Next
  204.     If cboDSNList.Text = "
  205. " Then
  206.         txtServer.Enabled = True
  207.         cboDrivers.Enabled = True
  208.     Else
  209.         txtServer.Enabled = False
  210.         cboDrivers.Enabled = False
  211.     End If
  212. End Sub
  213. Sub GetDSNsAndDrivers()
  214.     On Error Resume Next
  215.     Dim i As Integer
  216.     Dim sDSNItem As String * 1024
  217.     Dim sDRVItem As String * 1024
  218.     Dim sDSN As String
  219.     Dim sDRV As String
  220.     Dim iDSNLen As Integer
  221.     Dim iDRVLen As Integer
  222.     Dim lHenv As Long         '
  223.     cboDSNList.AddItem "
  224.     '
  225.  DSNs
  226.     If SQLAllocEnv(lHenv) <> -1 Then
  227.         Do Until i <> SQL_SUCCESS
  228.             sDSNItem = Space(1024)
  229.             sDRVItem = Space(1024)
  230.             i = SQLDataSources(lHenv, SQL_FETCH_NEXT, sDSNItem, 1024, iDSNLen, sDRVItem, 1024, iDRVLen)
  231.             sDSN = VBA.Left(sDSNItem, iDSNLen)
  232.             sDRV = VBA.Left(sDRVItem, iDRVLen)
  233.                 
  234.             If sDSN <> Space(iDSNLen) Then
  235.                 cboDSNList.AddItem sDSN
  236.                 cboDrivers.AddItem sDRV
  237.             End If
  238.         Loop
  239.     End If
  240.     '
  241.     If cboDSNList.ListCount > 0 Then
  242.         With cboDrivers
  243.             If .ListCount > 1 Then
  244.                 i = 0
  245.                 While i < .ListCount
  246.                     If .List(i) = .List(i + 1) Then
  247.                         .RemoveItem (i)
  248.                     Else
  249.                         i = i + 1
  250.                     End If
  251.                 Wend
  252.             End If
  253.         End With
  254.     End If
  255.     cboDSNList.ListIndex = 0
  256. End Sub
  257. Private Sub txtDatabase_Change()
  258. End Sub
  259.