
Please HELP. I am very frustrated !
I have written a small application using an Access8.0 database. I am
using DAO with no Data control or bound controls. The problem I am
having is if I edit a record from my form and save the changes then edit
the same record and save the changes I get a runtime error (3021) "No
record found".
I have posted this problem here and to the VB General Discussion Group
before and have gotten no response. I need to figure out this problem. I
have tried to research it through several books, I tried to find
information about the runtime error on Microsofts' site and I must be
doing something wrong there because I couldn't find the info.
Are people not responding because I am unknowingly doing something (or
not) that makes me a jerk ? I'm sure that I am not the only person who
has run across this problem so I am frustrated that no one is helping
me.
If anyone is reading this, if I am being stupid I really don't mean to
be. Also, thank you kindly in advance for any help you could provide.
Here is my code for the EDIT and SAVE buttons on the form:
Private Sub cmdEDIT_Click()
For Each CTL In Me.Controls
If TypeOf CTL Is TextBox Then
CTL.BackColor = vbYellow
CTL.Locked = False
End If
Next
Me.lblDistName.BackColor = vbYellow
Me.lblDistName.Caption = "EDIT " & Me.txtName.Text
Me.cmdADD.Enabled = False
Me.cmdDELETE.Enabled = False
Me.cmdEDIT.Enabled = False
'Me.cmdFIND.Enabled = False
Me.cmdCANCEL.Enabled = True
Me.cmdSAVE.Enabled = True
End Sub
Private Sub cmdSave_Click()
Dim tmpMsg
'*** Don't allow Save if no Distributor Name
If Me.txtName = "" Then
MsgBox "You must fill in a Distributor Name", , "PROBLEM !"
Me.txtName.SetFocus
Exit Sub
End If
'*** If User pressed Add New, save new record. If not, save edited
record
If Me.lblDistName.Caption = "ADD NEW DISTRIBUTOR" Then
RSDist.AddNew
Call FillRec
RSDist.Update
RSDist.Bookmark = RSDist.LastModified
Else
tmpMsg = MsgBox("Are you sure you want to save changes to this
record ?",
vbDefaultButton2 + vbYesNo)
If tmpMsg = vbYes Then
RSDist.Edit
Call FillRec
RSDist.Update
RSDist.Bookmark = RSDist.LastModified
End If
End If
'*** Format controls back to normal so user knows Save is complete.
For Each CTL In Me.Controls
If TypeOf CTL Is TextBox Then
CTL.BackColor = vbWhite
CTL.Locked = True
End If
Next
Me.lblDistName.BackColor = RGB(166, 202, 240)
Me.lblDistName.Caption = "DISTRIBUTOR"
Me.cmdADD.Enabled = True
Me.cmdDELETE.Enabled = True
Me.cmdEDIT.Enabled = True
'Me.cmdFIND.Enabled = True
Me.cmdCANCEL.Enabled = False
Me.cmdSAVE.Enabled = False
'*** Refresh the screeen with the new or modified record
Call FillScreen
'*** Refresh the list in the DistName combo box
Call FillCombo
End Sub