A better mouse trap? (1 Viewer)

Guillaume777

Registered User.
Local time
Yesterday, 19:04
Joined
May 4, 2006
Messages
23
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.
 

Guillaume777

Registered User.
Local time
Yesterday, 19:04
Joined
May 4, 2006
Messages
23
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 !
 

ghudson

Registered User.
Local time
Yesterday, 22:04
Joined
Jun 8, 2002
Messages
6,194
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!
 

carlchapman

Registered User.
Local time
Today, 03:04
Joined
Jul 25, 2006
Messages
29
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.
 

uplate

Registered User.
Local time
Yesterday, 22:04
Joined
Oct 23, 2006
Messages
21
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...
 

rhett7660

Still Learning....
Local time
Yesterday, 19:04
Joined
Aug 25, 2005
Messages
371
ghudson


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

Thank you again

R~
 

Medezark

New member
Local time
Yesterday, 22:04
Joined
Feb 25, 2009
Messages
1
;)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
 

kyuball

Registered User.
Local time
Yesterday, 19:04
Joined
Jul 6, 2009
Messages
66
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?
 

RuralGuy

AWF VIP
Local time
Yesterday, 20:04
Joined
Jul 2, 2005
Messages
13,825
Did you create a control named tbProperSave on your current form?
 

kyuball

Registered User.
Local time
Yesterday, 19:04
Joined
Jul 6, 2009
Messages
66
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?
 

RuralGuy

AWF VIP
Local time
Yesterday, 20:04
Joined
Jul 2, 2005
Messages
13,825
The upper left of ghudson's form has two TextBoxes. One hidden and one visible but *very* small so it can get the focus.
 

kyuball

Registered User.
Local time
Yesterday, 19:04
Joined
Jul 6, 2009
Messages
66
I can't seem to find the text box for tbhidden....
 

kyuball

Registered User.
Local time
Yesterday, 19:04
Joined
Jul 6, 2009
Messages
66
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?
 

kyuball

Registered User.
Local time
Yesterday, 19:04
Joined
Jul 6, 2009
Messages
66
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.
 

RuralGuy

AWF VIP
Local time
Yesterday, 20:04
Joined
Jul 2, 2005
Messages
13,825
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
 

kyuball

Registered User.
Local time
Yesterday, 19:04
Joined
Jul 6, 2009
Messages
66
It worked... thank you for all of your help!
 

Users who are viewing this thread

Top Bottom