M
Matthew DeAngelis
I am having some trouble with a series of DoCmd.RunSQL statements in
code. Basically, if I have these statements running consecutively,
sometimes only the first will run. Here is a sample procedure,
although the erratic behavior has happened to my other procedures with
the same structure:
Private Sub MakeDead_Click()
Dim cnn As ADODB.Connection
Dim VbMsgBoxStatus, AppendStatusOnReject, UpdateStatusDeadNoAction,
UpdateDateNotifySQL As String
Set cnn = CurrentProject.Connection
AppendStatusOnReject = "INSERT INTO [tbl: Data - StatusOnReject] (
DealID, DateReceived, Company, StatusBeforeReject, Priority, Interest
)" & _
" SELECT [tbl: Data - Deals].DealID, [tbl: Data -
Deals].DateReceived, [tbl: Data - Companies].Company, [tbl: Data -
Deals].Status, [tbl: Data - Deals].Priority, [tbl: Data -
Deals].Interest" & _
" FROM [tbl: Data - Companies] INNER JOIN [tbl:
Data - Deals] ON [tbl: Data - Companies].CompanyID = [tbl: Data -
Deals].CompanyID" & _
" WHERE ((([tbl: Data -
Deals].DealID)=[Forms]![frm: SpecificDeal]![DealID]));"
UpdateStatusDeadNoAction = "UPDATE [tbl: Data - Deals] INNER JOIN [tbl:
Data - StatusOnReject] ON [tbl: Data - Deals].DealID = [tbl: Data -
StatusOnReject].DealID SET [tbl: Data - Deals].Status = '6 - Dead/No
Action', [tbl: Data - StatusOnReject].StatusAfterReject = '6 - Dead/No
Action'" & _
" WHERE ((([tbl: Data -
Deals].DealID)=[Forms]![frm: SpecificDeal]![DealID]));"
UpdateDateNotifySQL = "UPDATE [tbl: Data - StatusOnReject] SET [tbl:
Data - StatusOnReject].DateNotice = Date()" & _
" WHERE ((([tbl: Data - StatusOnReject].DealID) =
[Forms]![frm: SpecificDeal]![DealID]))" & _
" WITH OWNERACCESS OPTION;"
VbMsgBoxStatus = MsgBox("Would you like to update this deal's status to
'Dead/No Action'?", vbYesNo)
If VbMsgBoxStatus = vbYes Then
If [Forms]![frm: SpecificDeal]![Status] Like "5 - To Reject" And
[Forms]![frm: SpecificDeal]![Personal] = True Then
DoCmd.SetWarnings WarningsOff
DoCmd.RunSQL UpdateDateNotifySQL
DoCmd.RunSQL UpdateStatusDeadNoAction
DoCmd.SetWarnings WarningsOn
AppendStatusOnReject = ""
UpdateStatusDeadNoAction = ""
Else
DoCmd.SetWarnings WarningsOff
DoCmd.RunSQL AppendStatusOnReject
DoCmd.RunSQL UpdateStatusDeadNoAction
DoCmd.SetWarnings WarningsOn
AppendStatusOnReject = ""
UpdateStatusDeadNoAction = ""
End If
End If
If VbMsgBoxStatus = vbNo Then
Exit Sub
End If
End Sub
With this particular statement, the Append query will run just fine,
meaning that it registers the change in the log, but then the Update
query will simply not run. I don't get any errors: the changes just
don't happen. It only happens sometimes, and going into the code and
back out without changing anything will sometimes fix it. Right now, I
have it so both queries run every time on my machine (Access 2002) and
seem to run every time on another machine (Access 2003), but only the
first one runs on a third machine (Access 2002). I do not know where
to begin in fixing this problem.
Any help would be much appreciated.
Matt
code. Basically, if I have these statements running consecutively,
sometimes only the first will run. Here is a sample procedure,
although the erratic behavior has happened to my other procedures with
the same structure:
Private Sub MakeDead_Click()
Dim cnn As ADODB.Connection
Dim VbMsgBoxStatus, AppendStatusOnReject, UpdateStatusDeadNoAction,
UpdateDateNotifySQL As String
Set cnn = CurrentProject.Connection
AppendStatusOnReject = "INSERT INTO [tbl: Data - StatusOnReject] (
DealID, DateReceived, Company, StatusBeforeReject, Priority, Interest
)" & _
" SELECT [tbl: Data - Deals].DealID, [tbl: Data -
Deals].DateReceived, [tbl: Data - Companies].Company, [tbl: Data -
Deals].Status, [tbl: Data - Deals].Priority, [tbl: Data -
Deals].Interest" & _
" FROM [tbl: Data - Companies] INNER JOIN [tbl:
Data - Deals] ON [tbl: Data - Companies].CompanyID = [tbl: Data -
Deals].CompanyID" & _
" WHERE ((([tbl: Data -
Deals].DealID)=[Forms]![frm: SpecificDeal]![DealID]));"
UpdateStatusDeadNoAction = "UPDATE [tbl: Data - Deals] INNER JOIN [tbl:
Data - StatusOnReject] ON [tbl: Data - Deals].DealID = [tbl: Data -
StatusOnReject].DealID SET [tbl: Data - Deals].Status = '6 - Dead/No
Action', [tbl: Data - StatusOnReject].StatusAfterReject = '6 - Dead/No
Action'" & _
" WHERE ((([tbl: Data -
Deals].DealID)=[Forms]![frm: SpecificDeal]![DealID]));"
UpdateDateNotifySQL = "UPDATE [tbl: Data - StatusOnReject] SET [tbl:
Data - StatusOnReject].DateNotice = Date()" & _
" WHERE ((([tbl: Data - StatusOnReject].DealID) =
[Forms]![frm: SpecificDeal]![DealID]))" & _
" WITH OWNERACCESS OPTION;"
VbMsgBoxStatus = MsgBox("Would you like to update this deal's status to
'Dead/No Action'?", vbYesNo)
If VbMsgBoxStatus = vbYes Then
If [Forms]![frm: SpecificDeal]![Status] Like "5 - To Reject" And
[Forms]![frm: SpecificDeal]![Personal] = True Then
DoCmd.SetWarnings WarningsOff
DoCmd.RunSQL UpdateDateNotifySQL
DoCmd.RunSQL UpdateStatusDeadNoAction
DoCmd.SetWarnings WarningsOn
AppendStatusOnReject = ""
UpdateStatusDeadNoAction = ""
Else
DoCmd.SetWarnings WarningsOff
DoCmd.RunSQL AppendStatusOnReject
DoCmd.RunSQL UpdateStatusDeadNoAction
DoCmd.SetWarnings WarningsOn
AppendStatusOnReject = ""
UpdateStatusDeadNoAction = ""
End If
End If
If VbMsgBoxStatus = vbNo Then
Exit Sub
End If
End Sub
With this particular statement, the Append query will run just fine,
meaning that it registers the change in the log, but then the Update
query will simply not run. I don't get any errors: the changes just
don't happen. It only happens sometimes, and going into the code and
back out without changing anything will sometimes fix it. Right now, I
have it so both queries run every time on my machine (Access 2002) and
seem to run every time on another machine (Access 2003), but only the
first one runs on a third machine (Access 2002). I do not know where
to begin in fixing this problem.
Any help would be much appreciated.
Matt