473,503 Members | 1,691 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, "Calculation 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 2066
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, "Calculation 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, "Calculation 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***@NOCARPkeithwilby.org.uk> wrote in message
news:co**********@sparta.btinternet.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, "Calculation 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, "Calculation 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_BeforeUpdate(Cancel 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***@NOCARPkeithwilby.org.uk> wrote in message
news:co**********@sparta.btinternet.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, "Calculation 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, "Calculation 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_BeforeUpdate(Cancel 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***@NOCARPkeithwilby.org.uk> wrote in message
news:co**********@sparta.btinternet.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_BeforeUpdate(Cancel 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+control2=control3
control4+control5=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***@NOCARPkeithwilby.org.uk> wrote in message
news:co**********@sparta.btinternet.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_BeforeUpdate(Cancel 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_BeforeUpdate(Cancel As Integer)

If MyCancel(Me.control1,Me.control2,Me.control3) Then Cancel = True

End Sub

Customise the above for whatever the control names are.

Function MyCancel(MyText1, 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, "Calculation 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+control2=control3
control4+control5=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***@NOCARPkeithwilby.org.uk> wrote in message
news:co**********@sparta.btinternet.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_BeforeUpdate(Cancel 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***@NOCARPkeithwilby.org.uk> wrote in message
news:co**********@sparta.btinternet.com...
You'd have to pass the control names to the function as arguments:

Private Sub txtMyTextBox_BeforeUpdate(Cancel As Integer)

If MyCancel(Me.control1,Me.control2,Me.control3) Then Cancel = True

End Sub

Customise the above for whatever the control names are.

Function MyCancel(MyText1, 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, "Calculation 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+control2=control3
control4+control5=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***@NOCARPkeithwilby.org.uk> wrote in message
news:co**********@sparta.btinternet.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_BeforeUpdate(Cancel 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
2289
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...
8
4033
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: ...
3
1727
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...
1
1359
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...
2
91015
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...
6
20036
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...
3
2286
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?...
2
3715
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...
2
3274
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...
7
6661
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...
0
7282
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,...
0
7339
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...
1
6995
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7463
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
4678
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...
0
3168
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3157
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1515
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
738
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.