Full Version: Pop Up Msg Box On Form
UtterAccess Forums > Microsoft® Access > Access Forms
AndrewHealey
Once again i look to the people of the forums excellent brains for knowledge laugh.gif
Am looking to add pop up boxes to my form if whatever the users enter is over a certain percent of something. Whats the correct way to do this?
Oneed to make the calculation as the only thing there at the moment is the beginning quantity and quantity 'x', so if 'x' as a percentage of the beginning quantity is greater then 'y' i want a pop up box telling the user to report to the supervisor.
thanks in advance,
andy
ScottGem
Use the After Update event of your control. Calculate the amount to compare then use an IF statement to check its its larger or not. Use a MsgBox function to issue the warning.
TH
jsitraining
Hi
If x > y Then
msgBox "Report to the supervisor"
Else
'other code
End If
HTH
Jim
AndrewHealey
nice one both, that works laugh.gif
ext question is, is there a way to show those values in the msg box. ie " x% are y. Maximum Allowance for Job Is z% - Report To Supervisor"
thanks again
andy
ScottGem
Dim strMsg As String
trMsg = x & "% are " & y & ". Maximum Allowance for Job is " & z & "%" & vbCrLf & "Report to Supervisor"
If x > y Then
msgBox strMsg, vbOkOnly, "Warning"
Else
'other code
End If
AndrewHealey
thanks scott i'll give it a go laugh.gif
ndy
ScottGem
glad to assist
AndrewHealey
how do i set the values x and y?
On the code at the moment i have
CODE
Private Sub ScrapOffset_AfterUpdate()
If (ScrapOffset / ForgingsIn) * 100 > 0.2 Then
MsgBox "x% of Forgings are Scrap Due To Offset . y% Maximum for this job. Quarintine & Report To Management"
Else
'other code
End If
End Sub

how do i assign x as scrapoffset and y as forgings in etc?
thanks
andy
AndrewHealey
sorry ignore me i think i've got it!
AndrewHealey
yeah i have got it but can anyone point me in the direction of a good article/tutorial for pop up boxes? i want to be able to set the box size, etc
Thanks scott and others!
andrew
ScottGem
You can't. The popup boxes created using the MsgBox and InputBox functions are static. They will expand to cover the amount of text that is in them. But other then the parameters listed for each function (see Help for those), you can't manipulate them further.
If you need to do so, then you will need to use a custom form. You can create unbound forms, remove the scroll boxes, record selectors,Control buttons, etc. Use the PopUp and modal properties to create your own custom message boxes.
HTH
AndrewHealey
k no problem scott.
Could this code be causing a confliction
CODE
  Private Sub ScrapOB_AfterUpdate()
strMsg = [ScrapOB] / [ForgingsIn] * 100 & "% are Scrap OB. Maximum Allowance for Job Is 0.1%. Quarantine Bin And Report To Management"
If (ScrapOB / ForgingsIn) * 100 > 0.1 Then
MsgBox strMsg, vbOKOnly, "Quarantine Bin"
Else
'other code
End If
End Sub
Private Sub ScrapOB_GotFocus()
strCtl = "ScrapOB"
End Sub

Has it seems to only bring up the msg box as and when it pleases!
thanks
andy
AndrewHealey
it works if u press enter off the box but not when u use the mouse to click to another
Mitchell
Try using an extra set of brackets in the if statement: Eg
If ((ScrapOB / ForgingsIn) * 100) > 0.1 Then
HTH
AndrewHealey
nah doesnt make any difference? :(
Mitchell
Hmmm....When you mouse click to another, are the contents of the ScrapOB control changing? If the contents of the control don't change, the AfterUpdate event won't run.

Does this help?
ScottGem
Have you tried stepping thru the code testing the values? I would also make this change:
!--c1-->
CODE
Private Sub ScrapOB_AfterUpdate()
Dim strMsg As String
Dim dblMaxAllow as Double
dblMaxAllow = ([ScrapOB] / [ForgingsIn]) * 100
strMsg = dblMax Allow & "% are Scrap OB. Maximum Allowance for Job Is 0.1%. Quarantine Bin And Report To Management"
If dblMaxAllow > 0.1 Then
     MsgBox strMsg, vbOKOnly, "Quarantine Bin"
Else
     'other code
End If
End Sub

Then step thru the code and see what dblMaxAllow equals.
HTH
AndrewHealey
sorry scott, i've made the changes, the 'stepping through the code' bit is new to me tho :|
ScottGem
Look up Debug in Access help for details on how to do this. If you are going to write code you NEED to learn how to debug it. This involves setting watch points and using the VBE to execute one line at a time.
TH
AndrewHealey
k will have a look at this this morning scott. any book suggestions? i wanna get a couple of decent ones but theres so many out there! on vba/vba for ms access?
a
andy
ScottGem
I like the Developer's Handbooks from Sybex
This is a "lo-fi" version of UA. To view the full version with more information, formatting and images, please click here.