473,320 Members | 1,868 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,320 software developers and data experts.

BeforeUpdate causes MouseClick to not execute

TheSmileyCoder
2,322 Expert Mod 2GB
Hi everyone, hope someone can help me.

Problem:
I have an event on a beforeUpdate of a textbox, which sets another hidden field on the same form. When my focus is in the textbox, and I click a command button, the beforeUpdate runs just fine, but it seems to 'Cancel' the click of the command button, so I have to press the command button once more.

The Textbox is a unbound field with the following code attached (Ignore any syntax errors, its typed from memory):
Expand|Select|Wrap|Line Numbers
  1. private sub tb_SetPassword_BeforeUpdate(Cancel)
  2.   if nz(me.tb_SetPassword,'')='' then
  3.     'Nothing
  4.   else
  5.     me.tb_Password=fstrEncrypt(me.tb_SetPassword)
  6.   end if 
  7. end sub
Purpose of the function is to take the typed password from the unbound field tb_SetPassword, encrypt it and store it in the bound (and hidden) field tb_Pasword, which will then be stored with the user record.

Other Details:
Using Access 2003.

How Can I make the clicked event fire as it should?
Dec 4 '09 #1

✓ answered by missinglinq

It does sound as if the BeforeUpdate event is grabbing control away from the command button and aborting its code. Does the button code fire on the first click if you don't enter anything into tb_SetPassword?

Linq ;0)>

9 2718
missinglinq
3,532 Expert 2GB
The Textbox is a unbound field with the following code attached (Ignore any syntax errors, its typed from memory):
I'm sorry, but this statement is simply inane. You expect us to troubleshoot your code, but you're only giving us the code as you remember it, not necessarily as it actually appears!

We also need to see the code attached to the command button, and possibly the code for the encryption function.

The one thing that stands out, in the code as you've posted it, is that

if nz(me.tb_SetPassword,' ')=' ' then

is going to cause a syntax error to be thrown. The two pairs of single quotes need to be double quotes.

if nz(me.tb_SetPassword,"")= "" then

I suppose that might be causing your problem, but as I said, we need to see the actual code for the items above in order to help you.

Welcome to Bytes!

Linq ;0)>
Dec 4 '09 #2
TheSmileyCoder
2,322 Expert Mod 2GB
Thanks for your reply.

The code throws no syntax errors.(but yes it is a doublequote) Ive tried added a msgbox event to the command button, which does not fire the first time i click it (but the beforeUpdate event of the textbox runs). Second time I click it, the msgbox will appear (and there will be no beforeUpdate on the textbox) and no error msg. I therefore conclude it has no impact what the code of the command button is.

It seems access has more focus on the fact that im leaving the textbox (triggering the beforeUpdate) then what im leaving it for (the command button).
Dec 4 '09 #3
missinglinq
3,532 Expert 2GB
It does sound as if the BeforeUpdate event is grabbing control away from the command button and aborting its code. Does the button code fire on the first click if you don't enter anything into tb_SetPassword?

Linq ;0)>
Dec 4 '09 #4
TheSmileyCoder
2,322 Expert Mod 2GB
Ok, tried changing code in the beforeUpdate of the textbox.

Expand|Select|Wrap|Line Numbers
  1. Private Sub tb_SetPassword_BeforeUpdate(Cancel As Integer)
  2.     Debug.Print "beforeupdaterun"
  3. end sub
The clicked command button would now fire correctly.

Changed it back to:
Expand|Select|Wrap|Line Numbers
  1. Private Sub tb_SetPassword_BeforeUpdate(Cancel As Integer)
  2.     Debug.Print "beforeupdaterun"
  3.     If Not Nz(Me.tb_SetPassword, "") = "" Then
  4.         Me.tb_UserPassword = MD5Hash(Me.tb_SetPassword)
  5.         Debug.Print "Setting Password"
  6.     End If
  7. End Sub
The Command button now requires too "clicks" before functioning. The odd thing is that my debug window actually shows the beforeupdaterun debug message, and the setting password twice, so it would seem the beforeupdate event runs each time.

I therefore tried to simply the issue, and take the MD5Hash out of the variables. Code now looks like this:
Expand|Select|Wrap|Line Numbers
  1. Private Sub tb_SetPassword_BeforeUpdate(Cancel As Integer)
  2.     Debug.Print "beforeupdaterun"
  3.     If Not Nz(Me.tb_SetPassword, "") = "" Then
  4.         'Me.tb_UserPassword = MD5Hash(Me.tb_SetPassword)
  5.         Me.tb_UserPassword = "Random String"
  6.         Debug.Print "Setting Password"
  7.     End If
  8. End Sub
I still need to click twice to get the command button to work.

And in response to your questin missinglinq, if the textbox is not dirty, the beforeupdate event is not fired, and the command button works fine.

I made yet another test, in which i "dirtyed" another field in the form before trying to change the password. The beforeupdate and command button would now both fire correctly. So maybe its related to dirtying the form (I have no event tied to dirty form or to the forms beforeupdate).

So, hope that ^^ made sense, and that someone has a good suggestion! :) And thanks for the posts made allready.
Dec 5 '09 #5
TheSmileyCoder
2,322 Expert Mod 2GB
In the end I solved this by adding a extra field to my table, one in which to write the password (in the form) but not store it.

The before update would then encode the password and store it in another field, after which it would wipe clean the field in which the user had actually written the password. This meant that the form would allready be dirty before the user clicked the save button. The mouseclick now executes as I want it too.
Jan 6 '10 #6
NeoPa
32,556 Expert Mod 16PB
TheSmileyOne:
I therefore conclude it has no impact what the code of the command button is.
Talk about Blythe Spirit. The issue here is not about how it affects you or your code. The universe does not begin and end with your person.

Your hastily posted code has been viewed and considered by a number of volunteer experts who now, it seems, have been wasting their time, simply to save you the bother of expressing your problem clearly and accurately.

Let me copy in a post I've had to use before for those that needed telling :
When posting any code on here please :
  1. Ensure you have Option Explicit set (See Require Variable Declaration).
  2. Try to compile it. If it doesn't compile for any reason please explain that clearly - including the error message and which line of your code it appears on. Compilation is done from the Visual Basic Editor menu - Debug \ Compile Project (Where Project is the actual name of your project).
  3. Copy your code (using the Clipboard - Cut / Copy / Paste) from your project directly into your post. Typing in code is not appreciated as it is likely to introduce typos which cause members to waste their time unnecessarily.
  4. Ensure that the code in your post is enveloped within CODE tags. The hash (#) button in the posting page helps with this. Simply select your code and click on the hash button to have it enveloped automatically.
If all these points are covered then all members will be better able to understand, and therefore attempt to answer, your question.

Administrator.
Jan 6 '10 #7
TheSmileyCoder
2,322 Expert Mod 2GB
The thread is about how when you run code that will dirty a form, it can cause the MouseClick event to not fire properly.

Yes, I will admit that I was wrong in posting code from memory instead of copy-pasting it, but missinglinq has allready bashed me for that once. You doing it again really serves no purpose besides boosting your ego and feeling superior.

Ive tried added a msgbox event to the command button, which does not fire the first time i click it (but the beforeUpdate event of the textbox runs). Second time I click it, the msgbox will appear (and there will be no beforeUpdate on the textbox) and no error msg. I therefore conclude it has no impact what the code of the command button is.
I do an analysis of when the code fires, and why it doesnt fire, and report my findings. I could have written anything in the code of the command button, which would not matter as it did not fire. In my oppinion it makes sense to report that since then I/we can focus our attention elsewhere.

While you are free to disagree I feel that I have done my best to express my problem as clearly and accurately as possible, and I have followed up on the issue with further analysis of my own, as well as posting when I found the underlying issue.

The BeforeUpdate of textbox tb_SetPassword (which is unbound and therefore does not give a dirty form when filled in) will update a bound field tb_UserPassword (and theryby dirtying the form). The dirtying of the form apparantly overrides/cancels the MouseClick operation. As written I eventually worked around it by making the tb_SetPassword into a bound field.
Jan 7 '10 #8
TheSmileyCoder
2,322 Expert Mod 2GB
It does sound as if the BeforeUpdate event is grabbing control away from the command button and aborting its code. Does the button code fire on the first click if you don't enter anything into tb_SetPassword?

Linq ;0)>
You where somewhat on the right track, so I choose your answer as the best reply. The BeforeUpdate of the TextBox dirtys the form, and as far as I could tell its the forms OnDirty event (with no code attached) that cancels the MouseClick, since dirtying the form otherwise before running the BeforeUpdate on the textbox would make the MouseClick execute properly.
Jan 7 '10 #9
NeoPa
32,556 Expert Mod 16PB
TheSmileyOne:
Yes, I will admit that I was wrong in posting code from memory instead of copy-pasting it, but missinglinq has allready bashed me for that once. You doing it again really serves no purpose besides boosting your ego and feeling superior.
Isn't it a shame that you didn't consider admitting that earlier, instead of arguing that it wasn't important anyway. That way I could happily have saved my effort. We quite like good manners here, and we try not to tolerate bad. You see that's bad for morale, as well as a bad example for any new posters reading through taking a note of the tone of our site. Hence we police this forum rigorously (to the best of our volunteer ability at least).

I wouldn't normally expect a relatively new member to understand that, but I would expect a little thought before jumping to wholly unwarranted conclusions.
TheSmileyOne:
I do an analysis of when the code fires, and why it doesnt fire, and report my findings. I could have written anything in the code of the command button, which would not matter as it did not fire. In my oppinion it makes sense to report that since then I/we can focus our attention elsewhere.

While you are free to disagree I feel that I have done my best to express my problem as clearly and accurately as possible, and I have followed up on the issue with further analysis of my own, as well as posting when I found the underlying issue.
I did notice that. I'm honestly impressed. That does put you a cut above the average poster and, were it not for the other comments, I would be keen to see more of you. As it is, I hope that your ego isn't too bruised and you do continue to post here, but know that we will continue to manage the site (and this forum particularly) rigorously. If you can live with that then Welcome to Bytes!
Jan 7 '10 #10

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

Similar topics

4
by: William Wisnieski | last post by:
Hello Everyone, Access 2000 I have a form with multiple pages on it. There is one text field on the third page of the form that I need the user to complete before leaving the form or moving...
15
by: simonmarkjones | last post by:
I want to validate my form using a BeforeUpdate event. However now that i call my code with a beforeupdate it wont let me go to next or previous records. What code should i put in o allow me...
4
by: Peter Rilling | last post by:
What is the difference between the MouseClick and Click events?
4
by: Chris Dunaway | last post by:
I added a MouseClick event to a Button control. It responds properly to the Left click of the button, but not a middle click or right click. Is it possible to get a right click and/or middle...
6
by: Kristian Frost | last post by:
Hi, I'm trying to add, as you might guess, mouseclick listeners to the shapes I am drawing using the GDI+ commands in a similar sort of way as could be done with the old VB "shapes". Problem is,...
2
by: GS | last post by:
how can I tell if it is right mouse click from left mouseclick? I would also to test if a key like control is being held down at the same time. what I would really like to is to capture control...
8
by: Michael R | last post by:
Dear users and experts, An unbound combo box in my form is responsible for changing a city name for an update query that creates a temprorary table which the form uses as its record source. In...
2
by: stovertl1 | last post by:
I am checking for null fields in a BeforeUpdate event handler. If I find one, I set Cancel=True, set the focus for the empty text box and exit the event handler. When I return to the form, there is...
6
by: RolltheBall | last post by:
Hi there. I am trying to make a certain symbol to appear upon every mouseclick. However, the symbol is a cross and an arrow head. This is how I tried to do it. Private Sub Form1_Paint(ByVal...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
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)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
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
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.