Firechief
05-13-2002, 09:56 AM
I am trying to fix an update bug in some Access code with no luck. I am very green with coding Access and this thing has me stumped. I have a "OK" click function to confirm the changes and then try to save the changes to an existing record. But, it changes the first record in the Table, not the one I expect it to. Here is what the code looks like. Any assistance would be appreciated.
Private Sub OK_Click()
On Error GoTo Err_Button71_Click
Const MB_OK = 0, MB_OKCANCEL = 1 ' Define buttons.
Const MB_YESNOCANCEL = 3, MB_YESNO = 4
Const MB_ICONSTOP = 16, MB_ICONQUESTION = 32 ' Define icons.
Const MB_ICONEXCLAMATION = 48, MB_ICONINFORMATION = 64
Const MB_DEFBUTTON2 = 256, IDYES = 6, IDNO = 7 ' Define other.
Title = "MsgBox Demo"
' Put together a sample message box with all the proper components.
Msg = "Do you want to save this record."
DgDef = MB_YESNO + MB_ICONSTOP + MB_DEFBUTTON2 ' Describe dialog box.
Title = ""
response = MsgBox(Msg, DgDef, Title) ' Get user response.
If response = IDYES Then ' Evaluate response
Dim MyTable As Recordset
Dim Mydb As Database
Set Mydb = DBEngine.Workspaces(0).Databases(0)
Set MyTable = Mydb.OpenRecordset("Employees", , dbOpenTable)
Dim iden As Variant
iden = Forms![Search_Employee]![Name_Code]
DoCmd.FindRecord Name_Code, , , , True
MyTable.Edit
MyTable![Name_Code] = Me![Last_Name] & " ," & Me![Middle_Name] & " ," & Me![First_Name] & " (" & Me![Location] & ")"
MyTable![Last_Name] = Me![Last_Name]
MyTable![First_Name] = Me![First_Name]
MyTable![Middle_Name] = Me![Middle_Name]
MyTable![Position] = Me![Position]
MyTable![Location] = Me![Location]
MyTable.Update
MyTable.Close
Msg = "Your record has been saved"
MsgBox Msg
Exit Sub
End If
Private Sub OK_Click()
On Error GoTo Err_Button71_Click
Const MB_OK = 0, MB_OKCANCEL = 1 ' Define buttons.
Const MB_YESNOCANCEL = 3, MB_YESNO = 4
Const MB_ICONSTOP = 16, MB_ICONQUESTION = 32 ' Define icons.
Const MB_ICONEXCLAMATION = 48, MB_ICONINFORMATION = 64
Const MB_DEFBUTTON2 = 256, IDYES = 6, IDNO = 7 ' Define other.
Title = "MsgBox Demo"
' Put together a sample message box with all the proper components.
Msg = "Do you want to save this record."
DgDef = MB_YESNO + MB_ICONSTOP + MB_DEFBUTTON2 ' Describe dialog box.
Title = ""
response = MsgBox(Msg, DgDef, Title) ' Get user response.
If response = IDYES Then ' Evaluate response
Dim MyTable As Recordset
Dim Mydb As Database
Set Mydb = DBEngine.Workspaces(0).Databases(0)
Set MyTable = Mydb.OpenRecordset("Employees", , dbOpenTable)
Dim iden As Variant
iden = Forms![Search_Employee]![Name_Code]
DoCmd.FindRecord Name_Code, , , , True
MyTable.Edit
MyTable![Name_Code] = Me![Last_Name] & " ," & Me![Middle_Name] & " ," & Me![First_Name] & " (" & Me![Location] & ")"
MyTable![Last_Name] = Me![Last_Name]
MyTable![First_Name] = Me![First_Name]
MyTable![Middle_Name] = Me![Middle_Name]
MyTable![Position] = Me![Position]
MyTable![Location] = Me![Location]
MyTable.Update
MyTable.Close
Msg = "Your record has been saved"
MsgBox Msg
Exit Sub
End If