Hi all, I am having a dilemma, I am trying to create a login form that accesses a MS Access database file. I believe that I have to use the ADO control... but I have no Idea where to start. Any help would be greatly appreciated.
: Hi all, I am having a dilemma, I am trying to create a login form that accesses a MS Access database file. I believe that I have to use the ADO control... but I have no Idea where to start. Any help would be greatly appreciated. :
Use ADO code rather than a control and set a reference to "Microsoft Activex Data Objects 2.x library"
[code] '9/12/02 - ADO CONNECTION TO ACCESS 'PASS [False] for unsercured db 'PASS [True] for a secured db - requires acccount/password Public Sub AdoConnectSecureDB(ByVal SecureDB As Boolean) 'SET DB AND SYSTEM PATHS Const cMyDBpath = "C:Tempdb1.mdb" Const cMySysMDW = "C:TempSystem.mdw"
Dim cn As ADODB.Connection, rs As ADODB.Recordset Dim sCon As String Dim MyAccount As String Dim MyPassword As String Dim errCount As Integer
On Error GoTo erh
Select Case SecureDB Case Is = False MyAccount = "Admin" MyPassword = "" Case Is = True MyAccount = "[ACCOUNT]" MyPassword = "[PASSWORD]" End Select
'CREATE NEW CONNECTION Set cn = New ADODB.Connection 'OPEN CONNECTION WITH CONNECTION STRING cn.Open sCon 'CREATE NEW RECORDSET Set rs = New ADODB.Recordset 'OPEN RECORDSET 'READ/WRITE 'rs.Open "TABLE1", cn, adOpenDynamic, adLockOptimistic, adCmdTable 'READ ONLY rs.Open "TABLE1", cn, adOpenStatic, adLockOptimistic, adCmdTable
'TRAVERSE RECORDS rs.MoveFirst Do While Not rs.EOF MsgBox rs!FIELD1 rs.MoveNext Loop
xit1: 'CLOSE rs.Close cn.Close xit2: 'RELEASE RESOURCES Set rs = Nothing Set cn = Nothing Exit Sub
erh: MsgBox Err.Description, vbExclamation, Err.Number errCount = errCount + 1 If errCount > 1 Then Resume xit2 Else Resume xit1 End Sub
Hello again, I believe I almost have this figured out, but one more problem persists. I have a form with two textboxes "txtusername" and "txtpassword" and I have a login button, when I hit the login button I want it to search through the database file to find the correct combination of username and password and then grant access to the main form. I do not want to be a pest, but I am still fairly new to all of this. Thank you.
: : Hi all, I am having a dilemma, I am trying to create a login form that accesses a MS Access database file. I believe that I have to use the ADO control... but I have no Idea where to start. Any help would be greatly appreciated. : : : : Use ADO code rather than a control and set a reference to "Microsoft Activex Data Objects 2.x library" : : [code] : '9/12/02 - ADO CONNECTION TO ACCESS : 'PASS [False] for unsercured db : 'PASS [True] for a secured db - requires acccount/password : Public Sub AdoConnectSecureDB(ByVal SecureDB As Boolean) : 'SET DB AND SYSTEM PATHS : Const cMyDBpath = "C:Tempdb1.mdb" : Const cMySysMDW = "C:TempSystem.mdw" : : Dim cn As ADODB.Connection, rs As ADODB.Recordset : Dim sCon As String : Dim MyAccount As String : Dim MyPassword As String : Dim errCount As Integer : : On Error GoTo erh : : Select Case SecureDB : Case Is = False : MyAccount = "Admin" : MyPassword = "" : Case Is = True : MyAccount = "[ACCOUNT]" : MyPassword = "[PASSWORD]" : End Select : : 'CONNECTION STRING : sCon = "Provider=Microsoft.Jet.OLEDB.4.0;" & _ : "User ID=" & MyAccount & ";Password=" & MyPassword & ";" & _ : "Data Source=" & cMyDBpath & ";" & _ : "Persist Security Info=False" : 'SECURE DB W/ SYSTEM.MDW? : If SecureDB = True Then sCon = sCon & ";Jet OLEDB:System database=" & cMySysMDW : : 'CREATE NEW CONNECTION : Set cn = New ADODB.Connection : 'OPEN CONNECTION WITH CONNECTION STRING : cn.Open sCon : 'CREATE NEW RECORDSET : Set rs = New ADODB.Recordset : 'OPEN RECORDSET : 'READ/WRITE : 'rs.Open "TABLE1", cn, adOpenDynamic, adLockOptimistic, adCmdTable : 'READ ONLY : rs.Open "TABLE1", cn, adOpenStatic, adLockOptimistic, adCmdTable : : 'TRAVERSE RECORDS : rs.MoveFirst : Do While Not rs.EOF : MsgBox rs!FIELD1 : rs.MoveNext : Loop : : xit1: : 'CLOSE : rs.Close : cn.Close : xit2: : 'RELEASE RESOURCES : Set rs = Nothing : Set cn = Nothing : Exit Sub : : erh: : MsgBox Err.Description, vbExclamation, Err.Number : errCount = errCount + 1 : If errCount > 1 Then Resume xit2 Else Resume xit1 : End Sub : : [/code] :
Comments
:
Use ADO code rather than a control and set a reference to "Microsoft Activex Data Objects 2.x library"
[code]
'9/12/02 - ADO CONNECTION TO ACCESS
'PASS [False] for unsercured db
'PASS [True] for a secured db - requires acccount/password
Public Sub AdoConnectSecureDB(ByVal SecureDB As Boolean)
'SET DB AND SYSTEM PATHS
Const cMyDBpath = "C:Tempdb1.mdb"
Const cMySysMDW = "C:TempSystem.mdw"
Dim cn As ADODB.Connection, rs As ADODB.Recordset
Dim sCon As String
Dim MyAccount As String
Dim MyPassword As String
Dim errCount As Integer
On Error GoTo erh
Select Case SecureDB
Case Is = False
MyAccount = "Admin"
MyPassword = ""
Case Is = True
MyAccount = "[ACCOUNT]"
MyPassword = "[PASSWORD]"
End Select
'CONNECTION STRING
sCon = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"User ID=" & MyAccount & ";Password=" & MyPassword & ";" & _
"Data Source=" & cMyDBpath & ";" & _
"Persist Security Info=False"
'SECURE DB W/ SYSTEM.MDW?
If SecureDB = True Then sCon = sCon & ";Jet OLEDB:System database=" & cMySysMDW
'CREATE NEW CONNECTION
Set cn = New ADODB.Connection
'OPEN CONNECTION WITH CONNECTION STRING
cn.Open sCon
'CREATE NEW RECORDSET
Set rs = New ADODB.Recordset
'OPEN RECORDSET
'READ/WRITE
'rs.Open "TABLE1", cn, adOpenDynamic, adLockOptimistic, adCmdTable
'READ ONLY
rs.Open "TABLE1", cn, adOpenStatic, adLockOptimistic, adCmdTable
'TRAVERSE RECORDS
rs.MoveFirst
Do While Not rs.EOF
MsgBox rs!FIELD1
rs.MoveNext
Loop
xit1:
'CLOSE
rs.Close
cn.Close
xit2:
'RELEASE RESOURCES
Set rs = Nothing
Set cn = Nothing
Exit Sub
erh:
MsgBox Err.Description, vbExclamation, Err.Number
errCount = errCount + 1
If errCount > 1 Then Resume xit2 Else Resume xit1
End Sub
[/code]
: : Hi all, I am having a dilemma, I am trying to create a login form that accesses a MS Access database file. I believe that I have to use the ADO control... but I have no Idea where to start. Any help would be greatly appreciated.
: :
:
: Use ADO code rather than a control and set a reference to "Microsoft Activex Data Objects 2.x library"
:
: [code]
: '9/12/02 - ADO CONNECTION TO ACCESS
: 'PASS [False] for unsercured db
: 'PASS [True] for a secured db - requires acccount/password
: Public Sub AdoConnectSecureDB(ByVal SecureDB As Boolean)
: 'SET DB AND SYSTEM PATHS
: Const cMyDBpath = "C:Tempdb1.mdb"
: Const cMySysMDW = "C:TempSystem.mdw"
:
: Dim cn As ADODB.Connection, rs As ADODB.Recordset
: Dim sCon As String
: Dim MyAccount As String
: Dim MyPassword As String
: Dim errCount As Integer
:
: On Error GoTo erh
:
: Select Case SecureDB
: Case Is = False
: MyAccount = "Admin"
: MyPassword = ""
: Case Is = True
: MyAccount = "[ACCOUNT]"
: MyPassword = "[PASSWORD]"
: End Select
:
: 'CONNECTION STRING
: sCon = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
: "User ID=" & MyAccount & ";Password=" & MyPassword & ";" & _
: "Data Source=" & cMyDBpath & ";" & _
: "Persist Security Info=False"
: 'SECURE DB W/ SYSTEM.MDW?
: If SecureDB = True Then sCon = sCon & ";Jet OLEDB:System database=" & cMySysMDW
:
: 'CREATE NEW CONNECTION
: Set cn = New ADODB.Connection
: 'OPEN CONNECTION WITH CONNECTION STRING
: cn.Open sCon
: 'CREATE NEW RECORDSET
: Set rs = New ADODB.Recordset
: 'OPEN RECORDSET
: 'READ/WRITE
: 'rs.Open "TABLE1", cn, adOpenDynamic, adLockOptimistic, adCmdTable
: 'READ ONLY
: rs.Open "TABLE1", cn, adOpenStatic, adLockOptimistic, adCmdTable
:
: 'TRAVERSE RECORDS
: rs.MoveFirst
: Do While Not rs.EOF
: MsgBox rs!FIELD1
: rs.MoveNext
: Loop
:
: xit1:
: 'CLOSE
: rs.Close
: cn.Close
: xit2:
: 'RELEASE RESOURCES
: Set rs = Nothing
: Set cn = Nothing
: Exit Sub
:
: erh:
: MsgBox Err.Description, vbExclamation, Err.Number
: errCount = errCount + 1
: If errCount > 1 Then Resume xit2 Else Resume xit1
: End Sub
:
: [/code]
: