Happy Codings - Programming Code Examples
Html Css Web Design Sample Codes CPlusPlus Programming Sample Codes JavaScript Programming Sample Codes C Programming Sample Codes CSharp Programming Sample Codes Java Programming Sample Codes Php Programming Sample Codes Visual Basic Programming Sample Codes

Visual Basic Programming Code Examples

Visual Basic > Applications VBA Code Examples

VB Application (Connection at 1st Startup)

VB Application (Connection at 1st Startup) Sub connectDB() On Error GoTo suji 'get the values from the registry dim con as new ADODB.connection Dim usrName$, dBaseNm$, svrNm$ usrName = GetSetting("MYAPP", "DBCON", "USRNM") dBaseNm = GetSetting("MYAPP", "DBCON", "DB") svrNm = GetSetting("MYAPP", "DBCON", "SVR") con.Open "Provider=SQLOLEDB.1;Persist Security Info=False;User ID=" & Trim(usrName) & ";Initial Catalog= " & Trim(dBaseNm) & ";Data Source=" & Trim(svrNm) If con.State = 1 Then MsgBox "Successfullly connected" Else MsgBox "check ur settings" GoTo suji End If Exit Sub suji: MsgBox Err.Description usrName = InputBox("Type the SQL User a/c", "User Name", "sa") dBaseNm = InputBox("Type the Database a/c", "Database Name", "tempDb") svrNm = InputBox("Type the SQL Server Name", "Server Name", "svr_01") SaveSetting "MYAPP", "DBCON", "USRNM", usrName SaveSetting "MYAPP", "DBCON", "DB", dBaseNm SaveSetting "MYAPP", "DBCON", "SVR", svrNm End Sub