473,569 Members | 2,772 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Message box Code

I have a message box which pops up a message after a check on a total. The
code on the Before Update Event is:
If ([txtDomfacsole] + [txtDomfacpart]) <> [txtDomfactot] Then
MsgBox "Row 1 does not add up" & vbCrLf & "It should be " & [txtDomfacsole]
+ [txtDomfacpart], vbOKCancel, "Calculatio n Error"
Cancel = True
End If
First Question
However I want the user to be able to accept the error if they wish, at the
moment this code keeps appearing as the user tabs to the next control. How
can I change the code so that the user has the choice as to whether or not
they want to change the data?

Second Question
I have some 14 rows, with totals, on a form where this calculation needs to
check the addition of various controls. I could of course put this code
behind every total but I wondered if there was a way to do this onec using a
module. If so could someone guide thru the creation of the module and what I
would have to put behind each total control.

TIA
Tony Williams
Nov 13 '05 #1
8 2072
Hi Tony.

Tony Williams wrote:
I have a message box which pops up a message after a check on a total. The
code on the Before Update Event is:
If ([txtDomfacsole] + [txtDomfacpart]) <> [txtDomfactot] Then
MsgBox "Row 1 does not add up" & vbCrLf & "It should be " & [txtDomfacsole]
+ [txtDomfacpart], vbOKCancel, "Calculatio n Error"
Cancel = True
End If
First Question
However I want the user to be able to accept the error if they wish, at the
moment this code keeps appearing as the user tabs to the next control. How
can I change the code so that the user has the choice as to whether or not
they want to change the data?
You need to use a Yes/No message box and tell the app to cancel the
transaction if the 'No' button is pressed:

If ([txtDomfacsole] + [txtDomfacpart]) <> [txtDomfactot] Then

If MsgBox("Row 1 does not add up" & vbCrLf & "It should be " &
[txtDomfacsole] + [txtDomfacpart] & " - Do you want to accept the
error?", vbYesNo, "Calculatio n Error") = vbNo Then Cancel = True

End If

The user can then use the ESC key to roll back the change(s) and correct
the entries. Question: why not use a query to do the calculations for
you so no calculation checking is needed?

Second Question
I have some 14 rows, with totals, on a form where this calculation needs to
check the addition of various controls. I could of course put this code
behind every total but I wondered if there was a way to do this onec using a
module. If so could someone guide thru the creation of the module and what I
would have to put behind each total control.

If you create a module then you won't have the luxury of the "Me"
keyword. Create a sub-routine in the form's code and call it from your
controls, eg:

Sub MyCalc()

Your code goes here

End Sub

HTH - Keith.
www.keithwilby.com
Nov 13 '05 #2
Thanks Keith. The first part works just fine. The reason I'm not using a
query for the calculation is because the users are keying in data from a
form that has been sent to them by outside organisations and they are
checking the data that has been submitted.
I'm not sure I understand the second part could you elaborate?
Thanks again
Tony
"Keith" <ke***@NOCARPke ithwilby.org.uk > wrote in message
news:co******** **@sparta.btint ernet.com...
Hi Tony.

Tony Williams wrote:
I have a message box which pops up a message after a check on a total. The code on the Before Update Event is:
If ([txtDomfacsole] + [txtDomfacpart]) <> [txtDomfactot] Then
MsgBox "Row 1 does not add up" & vbCrLf & "It should be " & [txtDomfacsole] + [txtDomfacpart], vbOKCancel, "Calculatio n Error"
Cancel = True
End If
First Question
However I want the user to be able to accept the error if they wish, at the moment this code keeps appearing as the user tabs to the next control. How can I change the code so that the user has the choice as to whether or not they want to change the data?


You need to use a Yes/No message box and tell the app to cancel the
transaction if the 'No' button is pressed:

If ([txtDomfacsole] + [txtDomfacpart]) <> [txtDomfactot] Then

If MsgBox("Row 1 does not add up" & vbCrLf & "It should be " &
[txtDomfacsole] + [txtDomfacpart] & " - Do you want to accept the
error?", vbYesNo, "Calculatio n Error") = vbNo Then Cancel = True

End If

The user can then use the ESC key to roll back the change(s) and correct
the entries. Question: why not use a query to do the calculations for
you so no calculation checking is needed?

Second Question
I have some 14 rows, with totals, on a form where this calculation needs to check the addition of various controls. I could of course put this code
behind every total but I wondered if there was a way to do this onec using a module. If so could someone guide thru the creation of the module and what I would have to put behind each total control.

If you create a module then you won't have the luxury of the "Me"
keyword. Create a sub-routine in the form's code and call it from your
controls, eg:

Sub MyCalc()

Your code goes here

End Sub

HTH - Keith.
www.keithwilby.com

Nov 13 '05 #3
Hi Tony, glad the first bit worked for you.

A sub-routine is a sequence of VBA code contained within an object such
as a form. The sub-routine is defined by "Sub" and the name you give it
followed by "()" and the "End Sub" statement. A simple example: if you
wanted all the text boxes on your form to cause the computer to beep and
then display a message box before they are updated, your sub-routine
might look like this:

Sub BeepMessage()

Beep
MsgBox("Data will now be updated.", vbOKOnly, "Data update"

End Sub

You would call the sub-routine from one of the controls' events, eg
'Before update':

Private Sub txtMyTextBox_Be foreUpdate(Canc el As Integer)

BeepMessage

End Sub

Not sure off the top of my head how to use a sub-routine to cancel an
event but I'll do a little digging and come back later.

Regards,
Keith.
www.keithwilby.com

Tony Williams wrote:
Thanks Keith. The first part works just fine. The reason I'm not using a
query for the calculation is because the users are keying in data from a
form that has been sent to them by outside organisations and they are
checking the data that has been submitted.
I'm not sure I understand the second part could you elaborate?
Thanks again
Tony
"Keith" <ke***@NOCARPke ithwilby.org.uk > wrote in message
news:co******** **@sparta.btint ernet.com...
Hi Tony.

Tony Williams wrote:
I have a message box which pops up a message after a check on a total.
The
code on the Before Update Event is:
If ([txtDomfacsole] + [txtDomfacpart]) <> [txtDomfactot] Then
MsgBox "Row 1 does not add up" & vbCrLf & "It should be " &
[txtDomfacsole]
+ [txtDomfacpart], vbOKCancel, "Calculatio n Error"
Cancel = True
End If
First Question
However I want the user to be able to accept the error if they wish, at
the
moment this code keeps appearing as the user tabs to the next control.
How
can I change the code so that the user has the choice as to whether or
not
they want to change the data?


You need to use a Yes/No message box and tell the app to cancel the
transaction if the 'No' button is pressed:

If ([txtDomfacsole] + [txtDomfacpart]) <> [txtDomfactot] Then

If MsgBox("Row 1 does not add up" & vbCrLf & "It should be " &
[txtDomfacsole] + [txtDomfacpart] & " - Do you want to accept the
error?", vbYesNo, "Calculatio n Error") = vbNo Then Cancel = True

End If

The user can then use the ESC key to roll back the change(s) and correct
the entries. Question: why not use a query to do the calculations for
you so no calculation checking is needed?

Second Question
I have some 14 rows, with totals, on a form where this calculation needs
to
check the addition of various controls. I could of course put this code
behind every total but I wondered if there was a way to do this onec
using a
module. If so could someone guide thru the creation of the module and
what I
would have to put behind each total control.


If you create a module then you won't have the luxury of the "Me"
keyword. Create a sub-routine in the form's code and call it from your
controls, eg:

Sub MyCalc()

Your code goes here

End Sub

HTH - Keith.
www.keithwilby.com


Nov 13 '05 #4
Looks like you'd need to use a function, not a sub:

Function MyCancel() As Boolean

Beep
If MsgBox("Are you sure you want to update the data?", vbYesNo, "Confirm
update") = vbNo Then MyCancel = True

End Function

The function returns "True" if the 'No' button is pressed.
You'd then call the function from your Before Update events:

Private Sub txtMyTextBox_Be foreUpdate(Canc el As Integer)

If MyCancel Then Cancel = True

End Sub

If 'MyCancel' returns 'True' then the event is cancelled. There may be a
more elegant way to do this, I'm sure someone will post it if there is ;-)

Regards,
Keith.
www.keithwilby.com

Keith wrote:

<snip>

Not sure off the top of my head how to use a sub-routine to cancel an
event but I'll do a little digging and come back later.

Regards,
Keith.
www.keithwilby.com

Nov 13 '05 #5
Thanks Keith I'll have a play around with that.
Tony
"Keith" <ke***@NOCARPke ithwilby.org.uk > wrote in message
news:co******** **@sparta.btint ernet.com...
Looks like you'd need to use a function, not a sub:

Function MyCancel() As Boolean

Beep
If MsgBox("Are you sure you want to update the data?", vbYesNo, "Confirm
update") = vbNo Then MyCancel = True

End Function

The function returns "True" if the 'No' button is pressed.
You'd then call the function from your Before Update events:

Private Sub txtMyTextBox_Be foreUpdate(Canc el As Integer)

If MyCancel Then Cancel = True

End Sub

If 'MyCancel' returns 'True' then the event is cancelled. There may be a
more elegant way to do this, I'm sure someone will post it if there is ;-)

Regards,
Keith.
www.keithwilby.com

Keith wrote:

<snip>

Not sure off the top of my head how to use a sub-routine to cancel an
event but I'll do a little digging and come back later.

Regards,
Keith.
www.keithwilby.com

Nov 13 '05 #6
One thought Keith each of the 14 rows have different control names in other
words it's the same type of calculation but different control names eg
control1+contro l2=control3
control4+contro l5=control6
and so on
How would I alter the formula from the first part of my question to use that
in a function to check all rows as they were entered?
Thanks
Tony
"Keith" <ke***@NOCARPke ithwilby.org.uk > wrote in message
news:co******** **@sparta.btint ernet.com...
Looks like you'd need to use a function, not a sub:

Function MyCancel() As Boolean

Beep
If MsgBox("Are you sure you want to update the data?", vbYesNo, "Confirm
update") = vbNo Then MyCancel = True

End Function

The function returns "True" if the 'No' button is pressed.
You'd then call the function from your Before Update events:

Private Sub txtMyTextBox_Be foreUpdate(Canc el As Integer)

If MyCancel Then Cancel = True

End Sub

If 'MyCancel' returns 'True' then the event is cancelled. There may be a
more elegant way to do this, I'm sure someone will post it if there is ;-)

Regards,
Keith.
www.keithwilby.com

Keith wrote:

<snip>

Not sure off the top of my head how to use a sub-routine to cancel an
event but I'll do a little digging and come back later.

Regards,
Keith.
www.keithwilby.com

Nov 13 '05 #7
You'd have to pass the control names to the function as arguments:

Private Sub txtMyTextBox_Be foreUpdate(Canc el As Integer)

If MyCancel(Me.con trol1,Me.contro l2,Me.control3) Then Cancel = True

End Sub

Customise the above for whatever the control names are.

Function MyCancel(MyText 1, MyText2, MyText3) As Boolean

If (MyText1 + MyText2) <> MyText3 Then

Beep
If MsgBox("Row 1 does not add up" & vbCrLf _
& "It should be " & MyText1 + MyText2 _
& " - Do you want to accept the error?", _
vbYesNo, "Calculatio n Error") = vbNo Then MyCancel = True

End If

End Function

Regards,
Keith.
www.keithwilby.com

Tony Williams wrote:
One thought Keith each of the 14 rows have different control names in other
words it's the same type of calculation but different control names eg
control1+contro l2=control3
control4+contro l5=control6
and so on
How would I alter the formula from the first part of my question to use that
in a function to check all rows as they were entered?
Thanks
Tony
"Keith" <ke***@NOCARPke ithwilby.org.uk > wrote in message
news:co******** **@sparta.btint ernet.com...
Looks like you'd need to use a function, not a sub:

Function MyCancel() As Boolean

Beep
If MsgBox("Are you sure you want to update the data?", vbYesNo, "Confirm
update") = vbNo Then MyCancel = True

End Function

The function returns "True" if the 'No' button is pressed.
You'd then call the function from your Before Update events:

Private Sub txtMyTextBox_Be foreUpdate(Canc el As Integer)

If MyCancel Then Cancel = True

End Sub

If 'MyCancel' returns 'True' then the event is cancelled. There may be a
more elegant way to do this, I'm sure someone will post it if there is ;-)

Regards,
Keith.
www.keithwilby.com

Keith wrote:

<snip>
Not sure off the top of my head how to use a sub-routine to cancel an
event but I'll do a little digging and come back later.

Regards,
Keith.
www.keithwilby.com


Nov 13 '05 #8
Thanks Keith I'll have a go at that
Tony
"Keith" <ke***@NOCARPke ithwilby.org.uk > wrote in message
news:co******** **@sparta.btint ernet.com...
You'd have to pass the control names to the function as arguments:

Private Sub txtMyTextBox_Be foreUpdate(Canc el As Integer)

If MyCancel(Me.con trol1,Me.contro l2,Me.control3) Then Cancel = True

End Sub

Customise the above for whatever the control names are.

Function MyCancel(MyText 1, MyText2, MyText3) As Boolean

If (MyText1 + MyText2) <> MyText3 Then

Beep
If MsgBox("Row 1 does not add up" & vbCrLf _
& "It should be " & MyText1 + MyText2 _
& " - Do you want to accept the error?", _
vbYesNo, "Calculatio n Error") = vbNo Then MyCancel = True

End If

End Function

Regards,
Keith.
www.keithwilby.com

Tony Williams wrote:
One thought Keith each of the 14 rows have different control names in other words it's the same type of calculation but different control names eg
control1+contro l2=control3
control4+contro l5=control6
and so on
How would I alter the formula from the first part of my question to use that in a function to check all rows as they were entered?
Thanks
Tony
"Keith" <ke***@NOCARPke ithwilby.org.uk > wrote in message
news:co******** **@sparta.btint ernet.com...
Looks like you'd need to use a function, not a sub:

Function MyCancel() As Boolean

Beep
If MsgBox("Are you sure you want to update the data?", vbYesNo, "Confirm
update") = vbNo Then MyCancel = True

End Function

The function returns "True" if the 'No' button is pressed.
You'd then call the function from your Before Update events:

Private Sub txtMyTextBox_Be foreUpdate(Canc el As Integer)

If MyCancel Then Cancel = True

End Sub

If 'MyCancel' returns 'True' then the event is cancelled. There may be a
more elegant way to do this, I'm sure someone will post it if there is ;-)
Regards,
Keith.
www.keithwilby.com

Keith wrote:

<snip>

Not sure off the top of my head how to use a sub-routine to cancel an
event but I'll do a little digging and come back later.

Regards,
Keith.
www.keithwilby.com


Nov 13 '05 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
2291
by: dmiller23462 | last post by:
My brain is nuked....Can anybody tell me right off the bat what is wrong with this code? Along with any glaring errors, please let me know the syntax to display a message (Response.Write would be fine I think) that will say "I'm sorry but the data you requested cannot be found" or something along those lines.... This code is on an archive...
8
4042
by: Steve | last post by:
I have several pairs of synchronized subforms in an application. I have a Delete button for each pair that uses the following code or similar to delete a record in the second subform: DoCmd.SetWarnings False DoCmd.RunCommand acCmdDeleteRecord DoCmd.SetWarnings True End If ExitHere: Me!SubName.SetFocus
3
1740
by: Serious_Practitioner | last post by:
Hello, all - A few days ago, I posted the following message - Hello all, and thank you for your help in the recent past. Got a new error message in the last few days. While working with different sized tables, in datasheet view, I've gotten this message -
1
1363
by: Serious_Practitioner | last post by:
Good day - As you suggested, I got and used the right version of Jetcomp, and I also tried to run compact and repair a couple of times. I think that the compact and repair process doesn't fully complete - there's a little progress bar in the lower left area of the status bar that gets about halfway done, and then stalls. It doesn't keep me...
2
91028
by: Janna Deegan | last post by:
Hello all, First off, if there is a better place to post for an answer to this question, please feel free to point me there. I have some very strange behavior happening with my System.web.mail objects. I was able to run my application fine for roughly 1500 email messages. The next time I tried sending mail, it stopped working with the...
6
20052
by: orekin | last post by:
Hi There I have been trying to come to grips with Application.Run(), Application.Exit() and the Message Pump and I would really appreciate some feedback on the following questions .. There are quite a few words in this post but the questions are actually quite similar and should be fairly quick to answer ... (1) What is Happening with...
3
2294
by: Marcos MOS | last post by:
Hi all, I would like show a message to user when the function's result return "false"... like this .... if (! my_function(params)) showMessage("my string message"); so, How Can I do it? Like, send a window's message or opening an other
2
3723
by: Mike Moore | last post by:
asp.net app - How do you get Java-side code to communicate with server-side code? I have tried numerous ways and examples, but have been unsuccessful. Therefore, unless I get real lucky and find another way of doing a messagebox, none of the existing ways will work with the code we have already written. Most all of the message box...
2
3281
by: Microsoft News | last post by:
What I have is a message box that pops up. It is another browser window. The code is a general function that you pass message, title and a key to. The box works great except, that if you are on a page, get the message box, then click ok on the message box go to another page and then back to the first page. The message box pops up again. It...
7
6671
by: Ralf Gedrat | last post by:
Hello! I have some Vb.Net applications, which are terminated at indefinite times without message. If I call in the program regulated system.GC.Collect, then the program is terminated here sporadically without message. It's not possible to debug in visual studio, i get no exceptions (application is terminated unexpectedly without...
0
7609
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7921
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8118
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
6278
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5504
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5217
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3636
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1208
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
936
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.