Results 1 to 3 of 3

Thread: need ur verification

  1. #1

    Thread Starter
    Member
    Join Date
    Aug 2000
    Location
    Penang, Malaysia
    Posts
    51

    Wink

    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

  2. #2
    Hyperactive Member Paul Warren's Avatar
    Join Date
    Jun 2000
    Location
    UK
    Posts
    282
    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.

    That's Mr Mullet to you, you mulletless wonder.

  3. #3
    Lively Member
    Join Date
    Jul 2000
    Location
    Stockholm, Sweden
    Posts
    83
    Why dont you select the record you want to edit from the first place ? I meen like "Select * from Customer where CustomerCode = " & txtDisplay1.Text.
    Yesterday, all my troubles seemed so far away...
    Help, I need somebody, Help...
    Now MCSD and still locking for intresting job in the south parts of Stockholm, Sweden.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width