thebatfink
Registered User.
- Local time
- Today, 07:48
- Joined
- Oct 2, 2008
- Messages
- 33
Hi, I am using a button to trigger an Update SQL statement. I'm worried about situations such as, it gets half way through and encouters an error updating a record - how I could recover from that.
I'm assuming that it attempt to perform the update looking for records that may cause an error 'before' actually performing the update on the records and that is the prompt saying 'you are about to update x records' etc. Is that correct?
If so, is it possible to supress this prompt and handle it in the VBA, ie, if no errors, just perform the update with no prompt, if there are errors then cancel the update for all records.
I want to avoid a user selecting to perform the run but not all the data being updated in one go. What I have so far is below (incidently, I inherited the database, I DID NOT name tables and fields with spaces and such in them!!
)..
I'm assuming that it attempt to perform the update looking for records that may cause an error 'before' actually performing the update on the records and that is the prompt saying 'you are about to update x records' etc. Is that correct?
If so, is it possible to supress this prompt and handle it in the VBA, ie, if no errors, just perform the update with no prompt, if there are errors then cancel the update for all records.
I want to avoid a user selecting to perform the run but not all the data being updated in one go. What I have so far is below (incidently, I inherited the database, I DID NOT name tables and fields with spaces and such in them!!

Code:
Private Sub ButtonUpRevision_Click()
Dim iReply As Integer
Dim dateString As String
dateString = DATE
iReply = MsgBox(Prompt:="Are you SURE you want to up revision and date" _
& vbCr & vbCr & "THIS CAN NOT BE UNDONE!!!", Buttons:=vbYesNo, title:="UP REVISION")
If iReply = vbYes Then
strSQL = _
"UPDATE [PRODUCT DATA] " & _
"SET [DATE] = """ + dateString + """, [ISSUEREVISION] = IIF([ISSUEREVISION] = ""N/A"",1,[ISSUEREVISION] + 1) " & _
"WHERE [R NAME] = """ + Me.R_NAME + """ AND MID([ITEM NO],1,1) <> ""O"" "
DoCmd.RunSQL strSQL
strSQL = _
"UPDATE [F2 PRODUCT DATA] " & _
"SET [DATE] = """ + dateString + """, [ISSUEREVISION] = IIF([ISSUEREVISION] = ""N/A"",1,[ISSUEREVISION] + 1) " & _
"WHERE [R NAME] = """ + Me.R_NAME + """ AND MID([ITEM NO],1,1) <> ""O"" "
DoCmd.RunSQL strSQL
MsgBox "Up revision and dating completed", vbInformation, title:="COMPLETE"
Else
MsgBox "Canceling", vbInformation, title:="CANCELLED"
Exit Sub
End If
End Sub