Continuous Subform Command Button Disappears When Edited Programmatically (1 Viewer)

DavidJMancini

Registered User.
Local time
Today, 13:11
Joined
Feb 3, 2017
Messages
12
SHORT:
So, the title pretty much says it all; I have a subform in continuous mode, each one having a command button to activate "that" item. Whenever I make a programmatic change to the command button's properties, it disappears entirely and never comes back without completely closing the form.

LONG:
The subform is sort of a "homemade" switchboard, in as much as that functionality seems to have been removed from Access 2013. (It uses a subform that displays records based on a query filter, rather than the old-style hard-coded command buttons with left-aligned labels.) I want to be able to edit these items by clicking a command button in the (sub)form header, which will shrink the "Open" command button (100% of each continuous item's width and height) down to a little box on the left that covers only the line item's icon, instead of the whole line. Then, some additional textboxes (for editing) are displayed.

When I click my mode-switching command button, all of the textboxes appear and disappear just fine; however, the command button, as said above, vanishes and never returns. It doesn't just become "transparent" — it vanishes completely: not see-able, not click-able, even if I only edited a property like "Width." And it doesn't come back until the form is completely closed and reopened.

Any thoughts on why this is happening?
 
Last edited:

CJ_London

Super Moderator
Staff member
Local time
Today, 20:11
Joined
Feb 19, 2013
Messages
16,553
Probably something to do with your code
 

MarkK

bit cruncher
Local time
Today, 13:11
Joined
Mar 17, 2004
Messages
8,178
The button has to be there, right? I don't believe you can remove a control from a form while the form is open and not in design view. Am I wrong?
So write code that reports on the button, where it is, what it's size is, what it's visible property is, etc....

First of all, open the locals window in the IDE. Then, write a routine like this in a standard module, set the breakpoint as indicated below, and run it...
Code:
private sub GetButtonData
   dim cmd as acccess.commandbutton

   set cmd = forms!yourform.cmdYourButtonName
[COLOR="Green"]   'set a breakpoint on the next line, the 'end sub' line[/COLOR]
end sub
...and with the code paused on the last line of the sub, look at the locals window, find the 'cmd' object in the tree. Expand it. There is a live view of all the properties of the control. Look at the .Visible property. Is the control visible? Look at the .Width property. Is the width greater than zero? Is the .Height property greater than zero? This way you can see exactly what is going on with that disappearing button.

Hope this helps,
 

DavidJMancini

Registered User.
Local time
Today, 13:11
Joined
Feb 3, 2017
Messages
12
Figured it out (on accident). The answer is TWIPS. Or, in other words, units of measurement sized at 1/1440th of an inch.

Turns out twips are the default unit of measurement (programmatically) for sizing Access controls in VBA!

If doing something like this:

Code:
[B][COLOR="RoyalBlue"]Me[/COLOR].[COLOR="royalblue"]txtFirstName[/COLOR].[COLOR="royalblue"]Width [/COLOR]= 5[/B] [COLOR="SeaGreen"]' Where 5 is "assumed" to be inches[/COLOR]

You must actually do this:

Code:
[B][COLOR="RoyalBlue"]Me[/COLOR].[COLOR="royalblue"]txtFirstName[/COLOR].[COLOR="royalblue"]Width [/COLOR]= 5 * 1440[/B] [COLOR="SeaGreen"]' This properly converts inches to twips[/COLOR]

No more disappearing controls - yay!!!
 

MarkK

bit cruncher
Local time
Today, 13:11
Joined
Mar 17, 2004
Messages
8,178
Good one! Thanks for posting back with your solution!
 

Users who are viewing this thread

Top Bottom