Re: Hide or show Control Button on Form in Access 97
From: Pete Sperling (PeteSperling_at_discussions.microsoft.com)
Date: 07/13/04
- Next message: T Hart: "Date stamp in a note field"
- Previous message: Scott Matheny: "Multitable form"
- In reply to: Nikos Yannacopoulos: "Re: Hide or show Control Button on Form in Access 97"
- Messages sorted by: [ date ] [ thread ]
Date: Tue, 13 Jul 2004 08:13:38 -0700
Nikos - Thanks for your help - Pete
"Nikos Yannacopoulos" wrote:
> Pete,
>
> To deal with the space in the subform name, change the reference to:
> Me.[Equipment F].Command7.Visible = True
>
> The underscore doesn't replace spaces, and I'm actually surpised you didn't
> get an error message saying Access can't find the control.
>
> HTH,
> Nikos
>
> "Pete Sperling" <PeteSperling@discussions.microsoft.com> wrote in message
> news:FE8D5AFC-7E83-4779-9DED-88D11853AD88@microsoft.com...
> > Nikos,
> > I corrected the code to read as follows:
> >
> > Private Sub Combo3_BeforeUpdate(Cancel As Integer)
> > If Me.Combo3 = "TRID-TBD REV 9.0G" Then
> > Me.Equipment_F.Command7.Visible = True
> > Else
> > Me.Equipment_F.Command7.Visible = False
> > End If
> > End Sub
> >
> > Command Button 7 does not disappear when Combo3 contains something other
> than TRID-TBD REV 9.0G. In case I didn't previously mention: Combo3 is in
> the Detail area of the Main Form and Command Button 7 is located in the Form
> Header of the Sub-Form. Should this make any difference in the code? Am I
> correct in using the BeforeUpdate event in the Main Form? Should I be using
> Underscore "_" between characters that have spaces or just put a space, i.e.
> Equipment F is the name of the sub-form but I am using Equipment_F in the
> code? Again, thanks for any assistance.
> > Pete
> >
> > I'm sure that once I can get one of the Command Buttons to appear and
> disappear I should have no problem adding the code for other Command
> Buttons.
> >
> >
> > "Nikos Yannacopoulos" wrote:
> >
> > > Pete,
> > >
> > > To begin with, apologies for the incomplete code! I missed out the Then:
> > >
> > > If Me.Combo3 = "TRID-TBD_REV_9.0G" Then
> > > etc.
> > >
> > > Now on to your new question: the code sample I rpovided yesterday for
> > > controlling the visibility of multiple buttons assumed they were all
> subject
> > > to the same "specific text" in the combo; if, as I understand now, it's
> a
> > > different text for each, then your code would have to have a separate
> > > If/Then/Else structure for each, like:
> > >
> > > If Me.Combo3 = "TRID-TBD_REV_9.0G" Then
> > > Me.Equipment_F.Command7.Visible = True
> > > Else
> > > Me.Equipment_F.Command7.Visible = False
> > > End If
> > >
> > > If Me.Combo3 = "specific text B" Then
> > > Me.Equipment_F.Command8.Visible = True
> > > Else
> > > Me.Equipment_F.Command8.Visible = False
> > > End If
> > >
> > > If Me.Combo3 = "specific text C" Then
> > > Me.Equipment_F.Command9.Visible = True
> > > Else
> > > Me.Equipment_F.Command9.Visible = False
> > > End If
> > >
> > > 'etc
> > > End Sub
> > >
> > > As I understand, you only want to have one button visible in each case;
> > > under the circumstances, a different approach, which I personally find
> > > neater, would be to make them all invisible, and then selectively make
> just
> > > one visible, rather than executing a series if If/Then/Else checks,
> like:
> > >
> > > Me.Equipment_F.Command7.Visible = False
> > > Me.Equipment_F.Command8.Visible = False
> > > Me.Equipment_F.Command9.Visible = False
> > > 'etc for additional buttons
> > >
> > > Select Case Me.Combo3
> > > Case "TRID-TBD_REV_9.0G"
> > > Me.Equipment_F.Command7.Visible = True
> > > Case "specific text B"
> > > Me.Equipment_F.Command8.Visible = True
> > > Case "specific text C"
> > > Me.Equipment_F.Command9.Visible = True
> > > 'etc for additional buttons
> > > End Select
> > > End Sub
> > >
> > > If you want to take this a step further and make your form look more
> > > "professional", you could use a single command button, and change its
> > > caption and what it does through code, based on the selected value in
> > > combo3. To do this, assuming you are only using one button called
> Command7,
> > > your button would always be visible, and the code behind the combo event
> and
> > > the form's current event would be something like:
> > >
> > > Select Case Me.Combo3
> > > Case "TRID-TBD_REV_9.0G"
> > > Me.Equipment_F.Command7.Caption = "Do action A..."
> > > Case "specific text B"
> > > Me.Equipment_F.Command7.Caption = "Do action B..."
> > > Case "specific text C"
> > > Me.Equipment_F.Command7.Caption = "Do action C..."
> > > 'etc for additional cases
> > > End Select
> > > End Sub
> > >
> > > Then, the code behind the command button itself would be something like:
> > >
> > > Select Case Me.Combo3
> > > Case "TRID-TBD_REV_9.0G"
> > > 'code for action A
> > > Case "specific text B"
> > > 'code for action B
> > > Case "specific text C"
> > > 'code for action C
> > > 'etc for additional cases
> > > End Select
> > > End Sub
> > >
> > > where you could include the actual code in the Select Case structure, or
> you
> > > could just call separate subs that contain the code pertaining to each
> > > selection.
> > >
> > > HTH,
> > > Nikos
> > >
> > > "Pete Sperling" <PeteSperling@discussions.microsoft.com> wrote in
> message
> > > news:46771D30-622A-420B-B23E-B0DA834784AC@microsoft.com...
> > > > Nikos,
> > > > I get - Compile error: Expected: Then or GoTo
> > > > when I entered the following:
> > > >
> > > > Private Sub Form_Current()
> > > > If Me.Combo3 = "TRID-TBD_REV_9.0G"
> > > > Me.Equipment_F.Command7.Visible = True
> > > > Else
> > > > Me.Equipment_F.Command7.Visible = False
> > > > End If
> > > > End Sub
> > > >
> > > > What do I need to do to fix? Where/how would I add a different text
> for
> > > Combo3 above in order to change the visible property of Command8,
> Command9,
> > > etc.. Thanks for your assistance. Pete
> > > >
> > > > "Nikos Yannacopoulos" wrote:
> > > >
> > > > > Pete,
> > > > >
> > > > > To your first question, assuming the subform is called SubForm1, the
> > > > > references to the command buttons on it should change to:
> > > > > Me.SubForm1.Formcmdbutton1
> > > > > etc, so the code would become:
> > > > >
> > > > > If Me.txtbox1 = "specific text"
> > > > > Me.SubForm1.cmdbutton1.Visible = True
> > > > > Else
> > > > > Me.SubForm1.cmdbutton1.Visible = False
> > > > > End If
> > > > >
> > > > > To do the same for multiple buttons, you could either repeat the
> line of
> > > > > code after the If / Else keywords, adding one for each button, like:
> > > > > If Me.txtbox1 = "specific text"
> > > > > Me.SubForm1.cmdbutton1.Visible = True
> > > > > Me.SubForm1.cmdbutton2.Visible = True
> > > > > Me.SubForm1.cmdbutton3.Visible = True
> > > > > Else
> > > > > Me.SubForm1.cmdbutton1.Visible = False
> > > > > Me.SubForm1.cmdbutton2.Visible = False
> > > > > Me.SubForm1.cmdbutton3.Visible = False
> > > > > End If
> > > > >
> > > > > For a big number of buttons you could employ a loop, but it's
> unlikely
> > > it's
> > > > > your case.
> > > > >
> > > > > HTH,
> > > > > Nikos
> > > > >
> > > > >
> > > > > "Pete Sperling" <PeteSperling@discussions.microsoft.com> wrote in
> > > message
> > > > > news:572D1AD7-C2D2-42E7-9A6B-992F5D686646@microsoft.com...
> > > > > > Nikos,
> > > > > > A couple of other questions - The command buttons in question are
> > > > > contained in the Form Header of a Sub-Form. The control that
> contains
> > > the
> > > > > specific test is located in the Main Form's Detail area. How is
> this
> > > going
> > > > > to affect the way the code is written? How do I add addtional
> > > "cmdbutton2,
> > > > > 3, 4, etc"? Unfortunately I have no background in writing code.
> Thanks
> > > for
> > > > > your assistance.
> > > > > >
> > > > > > "Nikos Yannacopoulos" wrote:
> > > > > >
> > > > > > > Pete,
> > > > > > >
> > > > > > > You will need a couple of line of code in the textbox control's
> > > Before
> > > > > > > Update event:
> > > > > > >
> > > > > > > If Me.txtbox1 = "specific text"
> > > > > > > Me.cmdbutton1.Visible = True
> > > > > > > Else
> > > > > > > Me.cmdbutton1.Visible = False
> > > > > > > End If
> > > > > > >
> > > > > > > I would suggest you use the same code in the form's On Current
> > > event, so
> > > > > the
> > > > > > > button is made visible.invisible according to the value of the
> field
> > > in
> > > > > each
> > > > > > > record as you browse through... or you could put the code in a
> > > private
> > > > > sub
> > > > > > > in the form's module, and call it from the two events (so you
> don't
> > > have
> > > > > to
> > > > > > > repeat it twice).
> > > > > > >
> > > > > > > HTH,
> > > > > > > Nikos
> > > > > > >
> > > > > > > "Pete Sperling" <PeteSperling@discussions.microsoft.com> wrote
> in
> > > > > message
> > > > > > > news:D49496FD-4E93-49E4-BDFD-C15B1A93D8F3@microsoft.com...
> > > > > > > > I have several control buttons on a form. I would like the
> > > control
> > > > > > > buttons to be hidden unless there is specific text in a control.
> > > How
> > > > > can I
> > > > > > > make the Visible property of these control buttons be "Yes"
> > > depending on
> > > > > the
> > > > > > > text in a control on the form and "No" if the text is other than
> the
> > > > > desired
> > > > > > > text. Any assistance greatly appreciated.
> > > > > > >
> > > > > > >
> > > > > > >
> > > > >
> > > > >
> > > > >
> > >
> > >
> > >
>
>
>
- Next message: T Hart: "Date stamp in a note field"
- Previous message: Scott Matheny: "Multitable form"
- In reply to: Nikos Yannacopoulos: "Re: Hide or show Control Button on Form in Access 97"
- Messages sorted by: [ date ] [ thread ]