473,324 Members | 1,646 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,324 software developers and data experts.

Syntax for msgbox Function

sickenhoofer
I am attempting to create a message box function to make sure that when a last name is changed, it is really the desired action. My syntax is below.

Private Sub ProviderLName_Change()
Dim bytReply As Byte
MsgBox "You have changed the LAST NAME for this provider." & vbCr & "Is this correct?", vbYesNo, "DATA CHANGE DETECTED"
If bytReply = 7 Then
Forms!frmProviderMainDataEntry!ProviderLName.Undo
Else
End If
End Sub

Upon testing, I changed the name. The message box appears. However, it does not undo the change. Can anyone tell me what I have done wrong?
Jul 16 '09 #1
9 6274
Sorry, I finally figured it out. I used the following.

Private Sub ProviderLName_Change()
Dim bytReply As Byte
bytReply = MsgBox("You have changed the LAST NAME for this provider." & vbCr & "Is this correct?", vbYesNo, "DATA CHANGE DETECTED")
If bytReply = 7 Then
Forms!frmProviderMainDataEntry!ProviderLName.Undo
Else
End If
End Sub
Jul 16 '09 #2
missinglinq
3,532 Expert 2GB
I believe you'll find out that your message box will fire with every letter you enter in the textbox, because that's when the OnChange event fires.It will also fire when you're first entering a name. I don't believe either of these are your intent. Try this:

Expand|Select|Wrap|Line Numbers
  1. Private Sub ProviderLName_BeforeUpdate(Cancel As Integer)
  2.  
  3. Dim bytReply As Integer
  4.  
  5.   If Me.ProviderLName.OldValue <> Me.ProviderLName.Value Then
  6.     bytReply = MsgBox("You have changed the LAST NAME for this provider." & vbCr & "Is this correct?", vbYesNo, "DATA CHANGE DETECTED")
  7.      If bytReply = vbNo Then
  8.        Me.ProviderLName.Undo
  9.        Cancel = True
  10.      End If
  11.   End If
  12.  
  13. End Sub
Jul 17 '09 #3
That is perfect. Thank you!

In my testing, I was only changing 1 character, just to see if it was working. So I did not catch the problem. Again, much appreciated!
Jul 17 '09 #4
missinglinq
3,532 Expert 2GB
Glad we could help!

Linq ;0)>
Jul 17 '09 #5
ADezii
8,834 Expert 8TB
@sickenhoofer
Just a couple of minor points to mention:
  1. The Return Value of the MsgBox() Function is an Integer.
  2. You may wish to make the Message Box a little more User Friendly and visually appealing, and at the same time the code more readable, as in:
    Expand|Select|Wrap|Line Numbers
    1. Private Sub ProviderLName_BeforeUpdate(Cancel As Integer)
    2. Dim intReply As Integer
    3. Dim strMsg As String
    4. Dim intButtons As Integer
    5.  
    6. strMsg = "You have changed the LAST NAME for the Provider [" & Me![ProviderLName].OldValue & _
    7.          "]." & vbCrLf & vbCrLf & "Is this correct?"
    8. intButtons = vbQuestion + vbYesNo + vbDefaultButton1
    9.  
    10. If Me![ProviderLName].OldValue <> Me!ProviderLName Then
    11.   intReply = MsgBox(strMsg, intButtons, "DATA CHANGE DETECTED")
    12.      If intReply = vbNo Then
    13.        Me.ProviderLName.Undo
    14.          Cancel = True
    15.      End If
    16. End If
    17. End Sub
Jul 17 '09 #6
ADezii . . . I tried this (as shown below), but I can't get it to work. Can you possibly tell me what I'm doing wrong?

I used a different name field so that I could test this before replacing the code on the last name field (working code).

Used this syntax:
Private Sub ProviderMiddleName_BeforeUpdate(Cancel As Integer)
Dim intReply As Integer
Dim strMsg As String
Dim intButtons As Integer

strMsg = "You have changed the LAST NAME for the provider [" & Me![ProviderMiddleName].OldValue & _
"]." & vbCrLf & vbCrLf & "Is this correct?"

intButtons = vbQuestion + vbYesNo + vbDefaultButton1

If Me!ProviderMiddleName.OldValue <> Me!ProviderMiddleName Then
intReply = MsgBox(strMsg, intButtons, "DATA CHANGE DETECTED")
If intReply = vbNo Then
Me!ProviderMiddleName.Undo
Cancel = True
End If
End If
End Sub

I checked for errors, but I'm just not seeing the problem. The result is that I can change or delete data and it does not respond at all.

I appreciate your feedback.
Jul 17 '09 #7
ADezii
8,834 Expert 8TB
@sickenhoofer
Rechecked the code again at my end, and all seems well. Puzzling... The only thing that pops up is your absolute Reference to the Control, but I cannot see how that would have a bearing on the code context. Let me get my thinking cap back on and I'll return later.
Jul 17 '09 #8
I tweaked it a little and was able to get it to work. Would you mind looking at this and let me know if you can see any problem with it? I am pretty new to VBA and want to make sure I don't have something out of order.

Private Sub ProviderMiddleName_BeforeUpdate(Cancel As Integer)
Dim intReply As Integer
Dim strMsg As String
Dim intButtons As Integer

intButtons = vbYesNo

strMsg = "You have changed the LAST NAME for the provider (" & Me![ProviderMiddleName].OldValue & _
")." & vbCrLf & vbCrLf & "Is this correct?"

intReply = MsgBox(strMsg, intButtons, "DATA CHANGE DETECTED")


If Me![ProviderMiddleName].OldValue <> Me!ProviderMiddleName Then
If intReply = vbNo Then
Me!ProviderMiddleName.Undo
Cancel = True
End If
End If
End Sub
Jul 17 '09 #9
ADezii
8,834 Expert 8TB
@sickenhoofer
Looks good to me, sickenhoofer. The only suggestion that I could make is that if you are only using the Yes/No Button Option, then there is no need for the Variable Declaration and Assignment:
Expand|Select|Wrap|Line Numbers
  1. Private Sub ProviderMiddleName_BeforeUpdate(Cancel As Integer)
  2. Dim intReply As Integer
  3. Dim strMsg As String
  4.  
  5. intButtons = vbYesNo
  6.  
  7. strMsg = "You have changed the LAST NAME for the provider (" & Me![ProviderMiddleName].OldValue & _
  8.          ")." & vbCrLf & vbCrLf & "Is this correct?"
  9.  
  10. intReply = MsgBox(strMsg, vbYesNo, "DATA CHANGE DETECTED")
  11.  
  12. If Me![ProviderMiddleName].OldValue <> Me!ProviderMiddleName Then
  13.   If intReply = vbNo Then
  14.     Me!ProviderMiddleName.Undo
  15.       Cancel = True
  16.   End If
  17. End If
  18. End Sub
Jul 17 '09 #10

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Sara | last post by:
Hi - Maybe it's my code, or maybe it's that I am not coding the Call to a sub in my code properly. Whichever, I am getting the error "Invalid Use of Null" when running this code. I do see my...
24
by: deko | last post by:
I'm trying to log error messages and sometimes (no telling when or where) the message contains a string with double quotes. Is there a way get the query to insert the string with the double...
12
by: Joe Fallon | last post by:
I would like to know the syntax to check that an Object is a String. If it was a number test I might use IsNumeric. But there is no function: IsString (is there?) -- Joe Fallon
2
by: Diana | last post by:
I thought I had this process pretty well down pat, but I'm getting a syntax error on the following code: *****Code***** 'Check for users - can't get this to work... Dim strUser As String ...
4
by: James | last post by:
What does this mean? 'To specify more than the first argument, you must use the MsgBox function in an expression' I'd love to see an example. Thanks!
14
by: DavidOwens | last post by:
Hi there everybody iv designed a database, curently when the delete button is pushed, it deletes the record completly, but i dont want that i want it to just disable the dispenser. iv crreated,...
2
by: GreggaR0und | last post by:
Hello; I am doing some data validation within InfoPath. One of my forms uses VBscript, not JScript, but I'm hoping this is still the best forum to post my issue. When I use the ReportError...
0
by: Gregg | last post by:
Hello; I have the below XML schema which I'm trying to iterate through node by node. The script I'm using is also shown below. The resulting output, also shown below, shows that I'm not...
1
by: =?Utf-8?B?U3RlcGhhbmllIERvaGVydHk=?= | last post by:
Hello World, I am trying to get all the shared printers for a remote Windows 2003 server using the EnumPrinters function and keep getting an error returned that corresponds to the message: "The...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

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.