Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Spooky Command Button Behavior

Status
Not open for further replies.

bhujanga

Programmer
Oct 18, 2007
181
US
This is the oddest thing I've ever seen. I have a form from which I want to open another form based on the active record in the first form. I do this all the time. I simply use the wizard to place a command button, tell it what I want it do and it does it.

Here's the thing. This time it refuses to filter the second form to the specified record - it just opens it with the entire record set. I do it over and over - same result.

But here's where it really gets weird. I had it working and then it quit working, had it working again - quit working. I finally figured out that if this third unrelated form happened to be open - even in design view - it worked. As soon as I closed that other form it no longer worked. As God is my witness, this third form is totally unrelated to what's going on and is not referenced in any way by either of the forms I'm working with. I mean really - how could anything that's only open in design view be affecting anything anyway?

So, I have clumsily solved the problem by having the command button open this third phantom form, then open the form I'm trying to open and then close the phantom form, so the phantom form is just seen for a second. But this is a ridiculous thing to have to do. Does anyone have a clue as to why it would behave this way?
 
Probably poor coding, especially if relying on wizards that write very generic code. A lot of vb code uses optional parameters to specify the object. If you do not specify the object you want referenced, the thing that gets referenced is the object with the focus and may not be the object you had in mind. For example you pop open three forms and in one of the forms you simply have
docmd.close
you expect the form to close, but instead some other form or object closes (which may cause other events). Good code would be
docmd.close acform, me.name
Which ensures the thing you expect to close is referenced and thus closes.
The wizard and novice coders tend to move focus to objects and then not explicitly reference them. Recommend you always explicitly reference the object you are working with. Do not assume or set focus as an implicit means.
 
when you use to command to open a form the acdialog on the end will not let you modify the first till you close the second.

Never give up never give in.

There are no short cuts to anything worth doing :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top