MsgBox Problems (1 Viewer)

Robbyp2001

Registered User.
Local time
Today, 13:35
Joined
Oct 8, 2011
Messages
143
Hello folks

I wonder if someone could tell me where I'm going wrong?

I have a command button that produces a MsgBox which should give the options to 'Proceed' or to 'Cancel'.

Here's what I have:

Private Sub Command10_Click()
If MsgBox("continue?", vbQuestion + vbYesNo) = vbYes Then

DoCmd.SetWarnings False
DoCmd.OpenQuery "NewDeliveryUpdate1", acViewNormal, acEdit
DoCmd.OpenQuery "NewDeliveryUpdate2", acViewNormal, acEdit
DoCmd.OpenQuery "NewDeliveryUpdate3", acViewNormal, acEdit
DoCmd.OpenQuery "NewDeliveryUpdate4", acViewNormal, acEdit
DoCmd.SetWarnings True

Else
MsgBox "Add New Stock Function aborted"

End If

Refresh
End Sub

Two things are happening.

1. When I run the queries from the button, without the MsgBox code, it works no problem and the record goes blank on the form as it has now been appended to a different table and the original is filtered out. This is not happening after the button (with the MsgBox code behind it) is clicked once.

2. I have discovered that the process works with the MsgBox code in place, but only after clicking the button twice.

I think this process should be fairly straightforward but clearly I am doing something wrong.

I just want to give the user the message that something is about to happen if they proceed, but they have the option to 'abort' the action and continue as normal.

Rob
 

static

Registered User.
Local time
Today, 10:35
Joined
Nov 2, 2015
Messages
823
Your msgbox code looks fine.
Add a breakpoint and step through the code.

Have you tried requery in place of/as well as refresh? (If the command is aborted you don't need to refresh/requery.)

If your query modifies data, you should use docmd.runsql
Or better yet currentdb.execute "queryname" which doesn't require you to turn off warnings.

Turning off warnings/user messages always runs the risk that they aren't turned back on if your code fails so should be avoided.
 

isladogs

MVP / VIP
Local time
Today, 10:35
Joined
Jan 14, 2017
Messages
18,261
Adding to static's comments:

I have discovered that the process works with the MsgBox code in place, but only after clicking the button twice.

Stepping through the code using breakpoints may help you see why.
However it may be that it works fine using that method.
If so, the issue may be that the PC does not have time to complete a task before starting the next
Try adding DoEvents after one or more items to fix that.
 
Last edited:

JHB

Have been here a while
Local time
Today, 11:35
Joined
Jun 17, 2012
Messages
7,732
By me your code works perfect without clicking the button twice.
Try a compact and repair, else create a new form and add the code.
If you still have to click the button twice, then post your database + description how to reproduce the fault.
You need to clarify what you want to refresh.
Code:
[B][COLOR=Red]Me.[/COLOR][/B]Refresh
 

Users who are viewing this thread

Top Bottom