Avatar of SweetingA
SweetingA

asked on 

VBA Controls (Combo Box Setting)

Is it possible to switch the controls of a combo box on/off in access vba.

IWhen i press button A i would like the combo box to display all records as normal.
When i press button B which jumps to a new record, i do not want the user to view all other records.
Microsoft Access

Avatar of undefined
Last Comment
Helen Feddema
Avatar of DatabaseMX (Joe Anderson - Former Microsoft Access MVP)
DatabaseMX (Joe Anderson - Former Microsoft Access MVP)
Flag of United States of America image

You can enable and disable (or visible not visible) any control. Is this what you mean?

mx
Something like this:

Private Sub Form_Current()
    If Me.NewRecord = True Then
        Me.Combo13.Enabled = False
    Else
        Me.Combo13.Enabled = True
    End If
End Sub


mx
ASKER CERTIFIED SOLUTION
Avatar of Rey Obrero (Capricorn1)
Rey Obrero (Capricorn1)
Flag of United States of America image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
OR ....

Private Sub btnA_Click()
    Me.Combo13.Enabled = True

End Sub


Private Sub btnB_Click()
    Me.Combo13.Enabled = False
    DoCmd.GoToRecord , , acNewRec
End Sub
You can do this, but it would involve changing the rowsource (and possibly other properties as well) of the combobox.
Not worth the trouble IMHO...


I would use MX's, suggestion of hiding the combobox, or simply enabling/disabling it:
("Greying" it out)

Me.YourCombo.Enabled=True
..and
Me.YourCombo.Enabled=False
...respectively
Sorry for the slow Dupe post Joe...

;-)
If the combo box is used for record selection, you could add a little option group (Filter or Select), so that the user's selection in the combo box either goes to the selected record (using code like the sample below), but lets you navigate to other records, or filters for just the selected record.
Private Sub cboSelect_AfterUpdate()
'Created by Helen Feddema 6-Apr-2010
'Last modified 24-Oct-2010

On Error GoTo ErrorHandler

   Dim strSearch As String

   strSearch = "[EventID] = " & Me.ActiveControl.Value

   'Find the record that matches the control
   Me.Recordset.FindFirst strSearch

ErrorHandlerExit:
   Exit Sub

ErrorHandler:
   MsgBox "Error No: " & Err.Number _
      & " in " & Me.ActiveControl.Name & " procedure; " _
      & "Description: " & Err.Description
   Resume ErrorHandlerExit

End Sub

Open in new window

Then, depending on the option selected, you would either do the FindFirst line or use strSearch to filter the recordset.
Microsoft Access
Microsoft Access

Microsoft Access is a rapid application development (RAD) relational database tool. Access can be used for both desktop and web-based applications, and uses VBA (Visual Basic for Applications) as its coding language.

226K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo