Hello,
what i am trying to do is I have a form set up where you enter in 3 types of information a name, errcode and a number. What I want to do is is when you enter in the record and then hit the save button it looks at the table that its saving to and finds out if there is already a matching record, if there is a matching record prompt the user if they would like to save over the record. Now i have this sort of working but the problem im having is either when I go to save it saves over the old record but for some as it saves over the old one it creates a new one. So I end up with two records or the other if I change some things I just get it to save new records and not save over the old one any help would be great.
here is the code im working with
also i have this in the Forms BeforeUpdate event
appreciate the help
what i am trying to do is I have a form set up where you enter in 3 types of information a name, errcode and a number. What I want to do is is when you enter in the record and then hit the save button it looks at the table that its saving to and finds out if there is already a matching record, if there is a matching record prompt the user if they would like to save over the record. Now i have this sort of working but the problem im having is either when I go to save it saves over the old record but for some as it saves over the old one it creates a new one. So I end up with two records or the other if I change some things I just get it to save new records and not save over the old one any help would be great.
here is the code im working with
also i have this in the Forms BeforeUpdate event
appreciate the help
Code:
If DCount("*", _
"[Table]", _
"(([Name]=" & Chr(34) & Me.Combo0 & Chr(34) & ") AND (" & _
"[Codetext]=" & Chr(34) & Me.Combo2 & Chr(34) & "))") > 0 Then
LResponse = MsgBox("This record already exists." & lvblf & _
" Would you like to overwrite this record?", vbYesNo + vbQuestion, "Overwrite")
If LResponse = vbNo Then
Cancel = True
Else
sql = "SELECT Name, Code, Num " & _
'"FROM [table] " & _
'"WHERE (([table]=" & Chr(34) & Me.Combo0 & Chr(34) & ") " & _
'"AND ([Codetxt]=" & Chr(34) & Me.Combo2 & Chr(34) & ") " & _
'"AND ([Num]=" & Chr(34) & Me.Text4 & Chr(34) & "))"
Set rst = CurrentDb.OpenRecordset(sql)
rst.AddNew
rst("Name") = Combo0
rst("Codetxt") = Combo2
rst("Number") = Text4
rst.Update
rst.Close
End If
End If
Comment