M
MVP - WannaB
I have this Code, it prompts a user if they enter a value in a field that is
not already present in the table, and allows them to add it or select from
the list. Everything works OK but the line commented adds a blank record
with the new value in the selected field.
MY QUESTION: I either need to delete that last record after this macro runs,
which is not a good idea. OR Capture the records index number and make that
the current record, and change the
rst.AddNew to rst.Edit
I have tested replacing the AddNew with Edit and as it runs now it modifies
the first record in the Table, so I could create a dummy record, and make
that the first record, but again a bad idea…
Can some one tell me how I can capture the index number (Primary Key Auto
Incremented for this table) of the current record and use that to ensure that
record is still the current record when the record it edited??
Here's my code>>>
Private Sub cbo_Progress_NotInList(NewData As String, Response As Integer)
Dim strmsg As String
Dim rst As Recordset
Dim DB As Database
Const MB_YESNO = 4
Const MB_Question = 32
Const IDNO = 7
strmsg = "'" & NewData & "' is not in list. "
strmsg = strmsg & "Would you like to add it?"
If MsgBox(strmsg, MB_YESNO + MB_Question + vbDefaultButton2, "ADD DATA")
= IDNO Then
Response = DATA_ERRDISPLAY
Else
Set DB = DBEngine.Workspaces(0).Databases(0)
Set rst = DB.OpenRecordset("2DO")
rst.AddNew <<This line adds a new record
rst("Progress") = NewData
rst.Update
Response = DATA_ERRADDED
rst.Close
End If
End Sub
not already present in the table, and allows them to add it or select from
the list. Everything works OK but the line commented adds a blank record
with the new value in the selected field.
MY QUESTION: I either need to delete that last record after this macro runs,
which is not a good idea. OR Capture the records index number and make that
the current record, and change the
rst.AddNew to rst.Edit
I have tested replacing the AddNew with Edit and as it runs now it modifies
the first record in the Table, so I could create a dummy record, and make
that the first record, but again a bad idea…
Can some one tell me how I can capture the index number (Primary Key Auto
Incremented for this table) of the current record and use that to ensure that
record is still the current record when the record it edited??
Here's my code>>>
Private Sub cbo_Progress_NotInList(NewData As String, Response As Integer)
Dim strmsg As String
Dim rst As Recordset
Dim DB As Database
Const MB_YESNO = 4
Const MB_Question = 32
Const IDNO = 7
strmsg = "'" & NewData & "' is not in list. "
strmsg = strmsg & "Would you like to add it?"
If MsgBox(strmsg, MB_YESNO + MB_Question + vbDefaultButton2, "ADD DATA")
= IDNO Then
Response = DATA_ERRDISPLAY
Else
Set DB = DBEngine.Workspaces(0).Databases(0)
Set rst = DB.OpenRecordset("2DO")
rst.AddNew <<This line adds a new record
rst("Progress") = NewData
rst.Update
Response = DATA_ERRADDED
rst.Close
End If
End Sub