R
Rice via AccessMonster.com
I'm having troulbe updating writing the code in VBA to update the record when
the user click my button. I'm using Access 2003. Please help.
Private Sub cmdModifyRecord_Click()
Dim ctrl As Control
Dim strsql As String
Dim adorst As ADODB.Recordset
Set adorst = New ADODB.Recordset
If IsNull(Me.LastName) Or Me.LastName = "" Then
MsgBox "You must enter a Last Name.", vbOKOnly, "Required Data"
Exit Sub
End If
If IsNull(Me.FirstName) Or Me.FirstName = "" Then
MsgBox "You must enter a First Name.", vbOKOnly, "Required Data"
Exit Sub
End If
If IsNull(Me.Password) Or Me.Password <> "password" Then
MsgBox "You must enter the default password.", vbOKOnly, "Required Data"
Exit Sub
End If
If IsNull(Me.txtAccess) Or Me.txtAccess = "" Then
MsgBox "You must enter an access level.", vbOKOnly, "Required Data"
Exit Sub
End If
adorst.ActiveConnection = CurrentProject.Connection
adorst.Open "tblEmpInfo", , adOpenDynamic, adLockOptimistic
If Me.lstEmpId.Value = adorst("EmpId").Value Then
'adorst.AddNew
strQL = "UPDATE tblEmpInfo SET " & _
"LastName = '" & Me.txtLastName & "', " & _
"FirstName'" & Me.txtFirstName & "', " & _
"Password'" & Me.txtPassword & "', " & _
"InactiveDate'" & Me.txtInactiveDate & "', " & _
"Inactive'" & Me.chkInactive & "', " & _
"Access'" & Me.txtAccess & "', " & _
"WHERE EmpId = " & Me.lstEmpId.Value"''"
DoCmd.OpenTable "tblEmpInfo", acViewNormal, acReadOnly
MsgBox "Employee ID Update! Review table and close.", vbOKOnly, "Modify
Employee Info"
End If
adorst.Close
Set adorst = Nothing
End Sub
the user click my button. I'm using Access 2003. Please help.
Private Sub cmdModifyRecord_Click()
Dim ctrl As Control
Dim strsql As String
Dim adorst As ADODB.Recordset
Set adorst = New ADODB.Recordset
If IsNull(Me.LastName) Or Me.LastName = "" Then
MsgBox "You must enter a Last Name.", vbOKOnly, "Required Data"
Exit Sub
End If
If IsNull(Me.FirstName) Or Me.FirstName = "" Then
MsgBox "You must enter a First Name.", vbOKOnly, "Required Data"
Exit Sub
End If
If IsNull(Me.Password) Or Me.Password <> "password" Then
MsgBox "You must enter the default password.", vbOKOnly, "Required Data"
Exit Sub
End If
If IsNull(Me.txtAccess) Or Me.txtAccess = "" Then
MsgBox "You must enter an access level.", vbOKOnly, "Required Data"
Exit Sub
End If
adorst.ActiveConnection = CurrentProject.Connection
adorst.Open "tblEmpInfo", , adOpenDynamic, adLockOptimistic
If Me.lstEmpId.Value = adorst("EmpId").Value Then
'adorst.AddNew
strQL = "UPDATE tblEmpInfo SET " & _
"LastName = '" & Me.txtLastName & "', " & _
"FirstName'" & Me.txtFirstName & "', " & _
"Password'" & Me.txtPassword & "', " & _
"InactiveDate'" & Me.txtInactiveDate & "', " & _
"Inactive'" & Me.chkInactive & "', " & _
"Access'" & Me.txtAccess & "', " & _
"WHERE EmpId = " & Me.lstEmpId.Value"''"
DoCmd.OpenTable "tblEmpInfo", acViewNormal, acReadOnly
MsgBox "Employee ID Update! Review table and close.", vbOKOnly, "Modify
Employee Info"
End If
adorst.Close
Set adorst = Nothing
End Sub