A better mouse trap?

Rich said:
I think you should know that adding quotes to Yes and No will make sure it doesn't work

I don't know what the heck you are talking about. "Yes" and "No" are text string, of course they need quotes ! Beside you totally miss the point as my code REPLACE the lines with the "Yes" and "No". Which means there is absolutly no "Yes" and "No" in my code.
 
Rich said:
True/False is the same as Yes/No without the quotes

Wow I never knew you could do that, even after years of working with VB ! Thanks for the tip !
 
Guillaume777 said:
Why did you use a hidden textbox ( tbProperSave ) ?

Instead I suggest you use a private variable.

Just delete that clunky textbox and instead add

Private ProperSave As Boolean

in the general declaration of your form ( just after option explicit )

Then all you need to do is change the

Me.tbProperSave.Value = "Yes"
Me.tbProperSave.Value = "No"


for

ProperSave = True
ProperSave = False
Why are you cluttering up this thread? My mouse trap sample is almost four years old. Using a text box makes it easy for a person to "display" while they are testing the functions. I always believe that there is always a better way to do most anything but... If it ain't broke, don't bother trying to fix it. :p

If your method works better for you... great, go with it and enjoy the rest of your day.

Also,

Yes/No
True/False
-1/0

They all give you the same result!
 
another minor loop hole

Hiya,

Soz for posting this thread if you have already seen the loop hole. When your tbproper was fixed by reseting it -

Me.tbProperSave.Value = "Yes"
DoCmd.RunCommand acCmdSaveRecord
Me.tbProperSave.Value = "No"
this worked fine on the main form.

I found another loop hole though, on the subform. Basicaly the same loop hole but in reverse to the main form.

I inserted the following snippet on the subform and now it appears to work fine. Try it.

Forms![fMouseTrap2WithSubforms]![tbProperSave].Value = "Yes"
DoCmd.RunCommand acCmdSaveRecord
Forms![fMouseTrap2WithSubforms]![tbProperSave].Value = "No"

Just reseting it the same as tbpropersave.
 
Timeless tip. I do have a question, though, on how to extend this idea.

What can you do when conditions in the application should prevent changing the record?

In other words, even when the record is not dirty, the user should not be allowed to move off that record until the other conditions are resolved.

Is there a way to prevent moving off a non-dirty record? What I want would be something like Form_BeforeRecordChange(Cancel As Integer), if only such a creature existed.

I thought about putting code in the ctl_Exit() sub for each field in the form, along with some code to determine which controls would be exiting to other fields on the same record, etc., etc. ... yuk! There must be a better way!

Thanks...
 
ghudson


Thank you.. and it is very easy to use and see what it going on.

Thank you again

R~
 
;)Short, sweet, and simple.
Occasionally doesn't work if you scroll the wheel extremely rapidly and continuously.
Place code below (or modify existing code if any) in the forms Code module.


Option Compare Database
Dim cur_record As Variant
'Where were we when the mousewheel moved?
Dim mouse_did_it As Boolean
'Did the mouse move the record, or something else?

Private Sub Form_Current()
'If the mouse moved it, then send us back to the current record
'and clear the mouse_did_it flag
If mouse_did_it = True Then
mouse_did_it = False
Me.Recordset.Bookmark = cur_record
End If

'make sure the mouse_did_it flag is empty
mouse_did_it = False

End Sub

'Capture any movement of the mousewheel
'and capture the current record's bookmark so that we can "undo" mouse moves
Private Sub Form_MouseWheel(ByVal Page As Boolean, ByVal Count As Long)
cur_record = Me.Bookmark
mouse_did_it = True
End Sub
 
First of all, thanks to ghudson for the code! I opened up the zip file and loved the way it worked!

The problem: I copied and pasted the code to one of my forms and then attempted to run it. Immediately, it gave me the following error message: "Compile error: Method or data member not found." Then it flips over to the VBA page and highlights the following:

Private Sub Form_Current()
On Error GoTo Err_Form_Current

Me.tbProperSave.Value = "No"

What am I doing wrong?
 
Did you create a control named tbProperSave on your current form?
 
Ummmm... I hate to sound like an idiot... but how would I go about doing that? And what about these references to tbHidden and such?
 
The upper left of ghudson's form has two TextBoxes. One hidden and one visible but *very* small so it can get the focus.
 
Take that back.. .found the little dot....

BTW, would it work if I were to set DoCmd.Close right above the Exit lines to make the buttons close the form altogther after they have made their choice?
 
And I really want to give you another major THANK YOU, Rural, for all of your help - major and minor (I know I can be a nuisance) - in this and the other thread.
 
BTW, would it work if I were to set DoCmd.Close right above the Exit lines to make the buttons close the form altogther after they have made their choice?
You could always give it a try. :p
 

Users who are viewing this thread

Back
Top Bottom