MS Access Forum / Forms / July 2007
Risk in using combo
|
|
Thread rating:  |
Frank Situmorang - 16 Jul 2007 09:10 GMT Hello:
I have an input form using combo, but it could happen the users or other people hit again the arrow head and choose another choice and the record was updated wrongly. My question is how can we avoide that people unintentionally modify the data say " supplier name". I know that there is something to change in the event property. But I do not really know how to make it. But again there is a situation that we intentionally need to change the data " supplier name " because we input it wrongly.
Thank you,
Frank
Ofer Cohen - 16 Jul 2007 09:42 GMT In the Combo BeforeUpdate event you can write the code if the data was changed, if so ask the user if he/she want to save it
If Not IsNull(Me.[ComboName].OldValue) Then If Me.[ComboName]<> Me.[ComboName].OldValue Then If MsgBox("The value was changed, Would you like to undo the changes?", vbYesNo) = vbYes Then ' Undo the changes SendKeys "{ESC}" End If End If End If
 Signature Good Luck BS"D
> Hello: > [quoted text clipped - 9 lines] > > Frank Frank Situmorang - 16 Jul 2007 10:56 GMT Ofer, you help me a lot, Thank you very much, I will try to do it now, but I think again, that it is good also for another field, like Inv# and amount field, is there any similar method like you gave me to be put in other fields other than combo?
Thanks in advance
Frank
> In the Combo BeforeUpdate event you can write the code if the data was > changed, if so ask the user if he/she want to save it [quoted text clipped - 22 lines] > > > > Frank Frank Situmorang - 16 Jul 2007 11:52 GMT Thank you Ofer, it works fatasticly, especially after I modified a bit, that it should be "no" to meet our needs.
Could you tell me how to make it that No is the default in the question, rather than Yes?, because people tendency is to click Yes without thinking.
Thanks a lot
Frank
> In the Combo BeforeUpdate event you can write the code if the data was > changed, if so ask the user if he/she want to save it [quoted text clipped - 22 lines] > > > > Frank Ofer Cohen - 16 Jul 2007 12:02 GMT Change the vbYes to vbNo. also, if you delete "= vbYes " and then write "=" you'll get the options for it (Yes or No)
If Not IsNull(Me.[ComboName].OldValue) Then If Me.[ComboName]<> Me.[ComboName].OldValue Then If MsgBox("Would you like to save the changes?", vbYesNo) = vbNo Then ' Undo the changes SendKeys "{ESC}" End If End If End If
> Thank you Ofer, it works fatasticly, especially after I modified a bit, that > it should be "no" to meet our needs. [quoted text clipped - 32 lines] > > > > > > Frank Klatuu - 16 Jul 2007 14:44 GMT That may not be sufficient. If you use one of the defaultbutton constants, you can control the default.
If MsgBox("Would you like to save the changes?", vbYesNo + vbQuestion + vbDefaultButton2) = vbNo
 Signature Dave Hargis, Microsoft Access MVP
> Change the vbYes to vbNo. > also, if you delete "= vbYes " and then write "=" you'll get the options for [quoted text clipped - 54 lines] > > > > > > > > Frank Ofer Cohen - 16 Jul 2007 19:06 GMT Hi Dave, I actullay misunderstood the question
Thanks
 Signature Good Luck BS"D
> That may not be sufficient. If you use one of the defaultbutton constants, > you can control the default. [quoted text clipped - 60 lines] > > > > > > > > > > Frank Klatuu - 16 Jul 2007 19:08 GMT really, wow, I haven't done that in ...hours :)
 Signature Dave Hargis, Microsoft Access MVP
> Hi Dave, > I actullay misunderstood the question [quoted text clipped - 65 lines] > > > > > > > > > > > > Frank John W. Vinson - 16 Jul 2007 19:54 GMT >If Not IsNull(Me.[ComboName].OldValue) Then > If Me.[ComboName]<> Me.[ComboName].OldValue Then [quoted text clipped - 5 lines] > End If >End If Just one minor tweak I'd suggest, Ofer - SendKeys is buggy, unreliable and unavailable in 2007. Instead of
SendKeys "{ESC}"
you can get the same effect more safely with
Me.[Comboname].Undo
John W. Vinson [MVP]
Ofer Cohen - 16 Jul 2007 20:04 GMT I know John, I tried it with a combo (Bounded) but for some reason it just didn't do it, it didn't return the ld value.
This is why I changed the approach to the SendKeys, which I know it buggy, but did the job that the Undo didn't
 Signature Good Luck BS"D
> >If Not IsNull(Me.[ComboName].OldValue) Then > > If Me.[ComboName]<> Me.[ComboName].OldValue Then [quoted text clipped - 16 lines] > > John W. Vinson [MVP] John W. Vinson - 17 Jul 2007 00:17 GMT >I tried it with a combo (Bounded) but for some reason it just didn't do it, >it didn't return the ld value. Odd! It works fine for me. It should restore the value of the combo to the value when the user first touched the record (NULL if it's a new record, previous value if not). I'll do some expermenting.
John W. Vinson [MVP]
Frank Situmorang - 17 Jul 2007 04:08 GMT Thanks to all of you who live in advanced countries. All your advices are beneficial to us who live in a developping country, Indonesia. Ofer's 1st advice works perfectly for me when I modified it a bit to be: = vbNo as below: If Not IsNull(Me.[ExpClass].OldValue) Then If Me.[ExpClass] <> Me.[ExpClass].OldValue Then If MsgBox("Anda telah merobah!!, apakah sengaja mau merobah?", vbYesNo) = vbNo Then ' Undo the changes SendKeys "{ESC}" End If End If End If
Again, Thanks a lot,
Frank
> >I tried it with a combo (Bounded) but for some reason it just didn't do it, > >it didn't return the ld value. [quoted text clipped - 4 lines] > > John W. Vinson [MVP] Frank Situmorang - 18 Jul 2007 09:02 GMT Ofer, It works for me, but now the side effect is the invoice no. field which is a primary key does not function, when I tried to type the same invoice number for the new record it can accept, while before if the same number it was rejected as it is a primary key.
Please help how can we solve the problem on this primary key.
On other things, why Winson said it is buggy.
Thanks,
Frank
> Change the vbYes to vbNo. > also, if you delete "= vbYes " and then write "=" you'll get the options for [quoted text clipped - 54 lines] > > > > > > > > Frank Ofer Cohen - 18 Jul 2007 09:32 GMT --It works for me, but now the side effect is the invoice no. field which is a --primary key does not function, when I tried to type the same invoice number --for the new record it can accept, while before if the same number it was --rejected as it is a primary key.
---Please help how can we solve the problem on this primary key. On the beforeUpdate event of the Invoice field, check if that value was already entered, look at this link for example code
"Preventing Duplicates from being entered" http://www.databasedev.co.uk/duplicates.html
--On other things, why Winson said it is buggy. John refred to SendKeys "{ESC}" That simulate you pressing the ESC key in the key board to return the old value, and his right. There is a command that used to return the old value (Undo) So, instead of using send keys, you can use Me.[ComboName].Undo
Before I posted the reply, the undo didn't return the old value (as it should) and this is why I used the ESC. You can try using the Undo, it might (and it should) work for you.
 Signature Good Luck BS"D
AccessVandal - 18 Jul 2007 11:03 GMT Hi Frank,
I don’t know what happened to the table. Check the primary key index property “Yes (No Duplicates)”.
Here is the solution without the sendkeys. The Me.ExpClass.Undo does not work and the codes given by Ofer Cohen doe not work in the BeforeUpdate Event. Instead use the AfterUpdate event in that combo box.
I have included the Me.Dirty just in case you need this. But it will also undo all changed fields in your form. Remove it if you don’t want to undo other fields/controls. But remember, the form is still “Dirty”, this means you got to manually press the “Esc” key else just simply ignore.
If Not IsNull(Me.CusID.OldValue) Then If Me.ExpClass <> Me.ExpClass.OldValue Then If MsgBox("You have change!!, Why purposely change?", vbYesNo) = vbYes Then ' Undo the changes Me.ExpClass = Me.ExpClass.OldValue ‘use this if there are no other changes in you form Me.Dirty = False End If End If End If
Note: Forgive me on the loose translation of Indonesian.
>Frank Situmorang wrote: >Ofer, [quoted text clipped - 16 lines] >> > > > >> > > > Frank
 Signature Please Rate the posting if helps you
Frank Situmorang - 18 Jul 2007 12:18 GMT Hi Vandal,
It seems that you understand Indonesian, where do you live actually?. I am in Jakarta, Indonesia.
You are right when I chekced the table which is already in the Back End ( in our server, I see that the Invoice number is no longer primarykey and duplicate is ok. How this could happen. Is that because I continues upgrading on my Front End?, and any VBA that can change it?, let say, like " Send Key "Esc" could change it?, I don't think so, or some body open the table and change the property?, I do not think there is one who understand about access.
Vandal, also the thing that I do not know yet, how can I make the default in the Yes/No buttons, I want the No button is the default, because when I make the one the Ofer proposed in the date field which uses pop up calender we can not chose No. button, because to pop up calender is double click.
Thanks in advance for your triggering my mind again.
Frank
> Hi Frank, > [quoted text clipped - 44 lines] > >> > > > > >> > > > Frank AccessVandal - 19 Jul 2007 02:15 GMT Hi Frank,
There was an incident with Forms/Subforms that might cause this problem. For example, this code from MS http://support.microsoft.com/kb/210236. This code will only work on a Single Form but if you use it on a MainForm with a Subform, it will change the Index property of that table. I’m unable to determine what causes it to change.
Note that I have miss out on “Me.Undo”. This will clear all the previous entry not the “Me.Dirty”.
If you do not want the user the change the data on that combo box, than use the “vbOKOnly”. As the “vbOKOnly” is only the default button, the users have only one choice.
Use it on the combo AfterUpdate event.
If Not IsNull(Me.CusID.OldValue) Then If Me.ExpClass <> Me.ExpClass.OldValue Then If MsgBox("You have change!!, Why purposely change?", vbOKOnly) = vbOK Then ' Undo the changes Me.ExpClass = Me.ExpClass.OldValue ‘use this if there are no other changes in you form Me.Undo ‘ undo all previous fields Me.Dirty = False End If End If End If
If Ofer’s code works for you with the send keys, than use that. But remember, the form is still “Dirty” if the users have also change other fields.
>Frank Situmorang wrote: >Hi Vandal, [quoted text clipped - 15 lines] > >Thanks in advance for your triggering my mind again.
 Signature Please Rate the posting if helps you
|
|
|