VERSION 5.00
Begin VB.Form frmMySQL 
   BorderStyle     =   3  'Fixed Dialog
   Caption         =   "mySQL Setup"
   ClientHeight    =   4170
   ClientLeft      =   45
   ClientTop       =   420
   ClientWidth     =   6030
   Icon            =   "frmMySQL.frx":0000
   LinkTopic       =   "Form1"
   MaxButton       =   0   'False
   MinButton       =   0   'False
   ScaleHeight     =   4170
   ScaleWidth      =   6030
   ShowInTaskbar   =   0   'False
   StartUpPosition =   1  'CenterOwner
   Begin VB.CommandButton Command2 
      Caption         =   "Delete Records"
      Height          =   495
      Left            =   3480
      TabIndex        =   14
      Top             =   3240
      Width           =   1575
   End
   Begin VB.CommandButton Command1 
      Caption         =   "Add Records"
      Height          =   495
      Left            =   1080
      TabIndex        =   13
      Top             =   3240
      Width           =   1695
   End
   Begin VB.Frame fraConnection 
      Caption         =   "Enter details to connect to MySQL DB"
      BeginProperty Font 
         Name            =   "MS Sans Serif"
         Size            =   8.25
         Charset         =   0
         Weight          =   700
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      ForeColor       =   &H000000FF&
      Height          =   2655
      Left            =   240
      TabIndex        =   6
      Top             =   240
      Width           =   5535
      Begin VB.TextBox txtHost 
         Height          =   285
         Left            =   2160
         TabIndex        =   0
         Top             =   345
         Width           =   3135
      End
      Begin VB.TextBox txtUser 
         Height          =   285
         Left            =   2160
         TabIndex        =   2
         Top             =   1320
         Width           =   2295
      End
      Begin VB.TextBox txtPassword 
         Height          =   285
         IMEMode         =   3  'DISABLE
         Left            =   2160
         PasswordChar    =   "*"
         TabIndex        =   3
         Top             =   1680
         Width           =   2295
      End
      Begin VB.TextBox txtPort 
         Height          =   285
         Left            =   2160
         TabIndex        =   4
         Text            =   "3306"
         Top             =   2040
         Width           =   615
      End
      Begin VB.CommandButton cmdConnect 
         Caption         =   "Connect"
         Default         =   -1  'True
         Height          =   255
         Left            =   4320
         TabIndex        =   5
         Top             =   2280
         Width           =   855
      End
      Begin VB.TextBox txtDB 
         Height          =   285
         IMEMode         =   3  'DISABLE
         Left            =   2160
         TabIndex        =   1
         Top             =   960
         Width           =   3135
      End
      Begin VB.Label Label1 
         Alignment       =   1  'Right Justify
         Caption         =   "Host/Server Name:"
         BeginProperty Font 
            Name            =   "Verdana"
            Size            =   8.25
            Charset         =   0
            Weight          =   700
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   255
         Index           =   0
         Left            =   120
         TabIndex        =   12
         Top             =   360
         Width           =   1935
      End
      Begin VB.Label Label1 
         Alignment       =   1  'Right Justify
         Caption         =   "User:"
         BeginProperty Font 
            Name            =   "Verdana"
            Size            =   8.25
            Charset         =   0
            Weight          =   700
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   255
         Index           =   1
         Left            =   600
         TabIndex        =   11
         Top             =   1320
         Width           =   1455
      End
      Begin VB.Label Label1 
         Alignment       =   1  'Right Justify
         Caption         =   "Password:"
         BeginProperty Font 
            Name            =   "Verdana"
            Size            =   8.25
            Charset         =   0
            Weight          =   700
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   255
         Index           =   2
         Left            =   600
         TabIndex        =   10
         Top             =   1680
         Width           =   1455
      End
      Begin VB.Label Label1 
         Alignment       =   1  'Right Justify
         Caption         =   "Port:"
         BeginProperty Font 
            Name            =   "Verdana"
            Size            =   8.25
            Charset         =   0
            Weight          =   700
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   255
         Index           =   3
         Left            =   600
         TabIndex        =   9
         Top             =   2040
         Width           =   1455
      End
      Begin VB.Label Label1 
         Alignment       =   1  'Right Justify
         Caption         =   "Database Name:"
         BeginProperty Font 
            Name            =   "Verdana"
            Size            =   8.25
            Charset         =   0
            Weight          =   700
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   255
         Index           =   4
         Left            =   360
         TabIndex        =   8
         Top             =   960
         Width           =   1695
      End
      Begin VB.Label Label3 
         Alignment       =   2  'Center
         Caption         =   "(IP address may be used)"
         BeginProperty Font 
            Name            =   "Arial"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   255
         Left            =   2160
         TabIndex        =   7
         Top             =   600
         Width           =   3135
      End
   End
End
Attribute VB_Name = "frmMySQL"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit

Dim modCNN As Connection

Private Sub Command1_Click()
Dim i As Integer
On Error GoTo ErrorTrap:

modCNN.Execute "BEGIN"

For i = 1 To 5
    modCNN.Execute "INSERT INTO `table1`(`test1`) VALUES (" & i & ")" '& strTemp
    If i = 3 Then MsgBox "Remove network cable and then press OK", vbInformation
Next i

modCNN.Execute "COMMIT"

MsgBox "Insert network cable and then press OK"

Exit Sub

ErrorTrap:
    MsgBox Err.Description

End Sub

Private Sub Command2_Click()
On Error GoTo ErrorTrap:

modCNN.Execute "BEGIN"
modCNN.Execute "DELETE FROM `table1`"
modCNN.Execute "COMMIT"

Exit Sub

ErrorTrap:
    MsgBox Err.Description

End Sub

Private Sub Form_Unload(Cancel As Integer)

'Cleanup
modCNN.Close
Set modCNN = Nothing
Set frmMySQL = Nothing

End Sub


Private Sub cmdConnect_Click()

On Error GoTo Hell

'Make sure values have been filled in
If NotComplete Then Exit Sub


Dim sql As String

'connect to MySQL server using MySQL ODBC 3.51 Driver
Set modCNN = New Connection
modCNN.ConnectionString = "DRIVER={MySQL ODBC 3.51 Driver};" _
                      & "SERVER=" & txtHost.Text & ";" _
                      & " DATABASE=" & txtDB.Text & ";" _
                      & " PORT=" & txtPort.Text & ";" _
                      & "UID=" & txtUser.Text & ";PWD=" & txtPassword.Text & "; OPTION=3"

modCNN.Open

'Test for open connection
If (modCNN.State And adStateOpen) = adStateOpen Then
    'Success
    MsgBox "Connection to mySQL database successfull!", vbInformation, "Success"
Else
    MsgBox "Connection to mySQL database failed!", vbInformation, "Failed"
End If

Exit Sub

Hell:
    MsgBox "Connection to mySQL database failed!", vbInformation, "Failed"
    
End Sub


Private Sub txtPort_Change()

'Check for numeric value
If Not IsNumeric(txtPort.Text) Then txtPort.Text = ""

End Sub

Private Function NotComplete() As Boolean

If Len(txtHost.Text) = 0 Or Len(txtPort.Text) = 0 Or _
    Len(txtUser.Text) = 0 Or Len(txtPassword.Text) = 0 Or Len(txtDB.Text) = 0 Then
    
    NotComplete = True
    
    'Msgbox
    MsgBox "All fields must be completed", vbCritical, "Invalid Entry"
End If

End Function


