PDA

Click to See Complete Forum and Search --> : need ur verification


leeckeat
Aug 15th, 2000, 09:07 PM
here is the my edit coding but it have minor problem where when i edit the existing data which i put empty on data field (customer name), it suppose to show me error message.
But when i run it, it will display the 'record edited' message before showing me the error message. What part is wrong in my code? need ur guide..TQ

On Error GoTo EditErr

'Open customer recordset to save edited record
Set rstTemp = Db.OpenRecordset("Select * from Customer", dbOpenDynaset)

With rstTemp
Do While Not .EOF
.Edit
If !CustomerCode = txtDisplay1.Text Then
!CustomerName = txtDisplay2.Text
MsgBox "Record Edited", vbOKOnly, "Customer"
End If
.Update
.MoveNext
Loop
End With
txtDisplay1.Text = ""
txtDisplay2.Text = ""

EditErr:
If Err.Number = 3315 Then
MsgBox "Data field can't be empty, please try again!",
vbOKOnly + vbCritical, "Error Message"
End If

Paul Warren
Aug 16th, 2000, 03:09 AM
leeckeat - without testing it myself I'd say that your problem doesn't occur until after the Msgbox because VB doesn't check the values until you try to perform the update itself. Try moving the .Update up a few lines up, to just after the line '!CustomerName = txtDisplay2.Text'. You'll need to move the .Edit inside the If statement aswell or it might not find a matching .Update before the next .Edit.
In fact, given the way it's written it makes sense to put the .Edit inside the If statement aswell because if the clause isn't true then the record isn't edited.

AKA
Aug 16th, 2000, 08:08 AM
Why dont you select the record you want to edit from the first place ? I meen like "Select * from Customer where CustomerCode = " & txtDisplay1.Text.