Multiple Combobox selection Acess VBA - vba

I am trying to create a VBA code that says, if combobox equals this or this or this then have radio button populate. When i use only one bucket (134) it works fine but when i try ti add multiple sections, i get and err.
My code:
If Me.cmbBucketFilter = "134,135,136" Then
'Working Echo Triggers
Me.fmeReached.Visible = True
Me.fmeRecovered.Visible = True
Me.fmeError.Visible = False
Else
'Working Another Bucket
Me.fmeError.Visible = True
Me.fmeReached.Visible = False
Me.fmeRecovered.Visible = False
End If

You're asking it to run only if cmbBucketFilter equals "134, 135, 136" (which it never can). What you really want is for it to run if it equals any of those values.
Change the first line to this:
If Me.cmbBucketFilter IN ("134", "135", "136") Then

Related

How can I set visible = true for only this record in MS Access?

I want to be able to add more fields depending on how many cars this employee have.
I tried set Me.textfield.Visible = True
So it initiates with Visible = False, then when the button '+' is pressed the textfield is shown, but it won't work how I expected
When I do :
Private Sub mostracarro2_Click()
Me.labelmodelo2.Visible = True
Me.Modelo2.Visible = True
Me.labelplaca2.Visible = True
Me.Placa2.Visible = True
Me.mostracarro3.Visible = True
End Sub
All of the others records fields are set for true, but I just wanted to change this record field.
If a employee has just one single car I want just one text field to be shown.
If a employee has more than one car I want to have two text field to be shown.
how can I do it in MS Access 2010?

MS Access vba code error with visible invisible VBA code

I have a filed called application. I have written code in vba to make the other field "application_txt" field visible and invisible if a particular value from application field is selected. But for this particulat field application when I write the below code in vba it throws the error. I dont understand why. It works fine for the other fields. Below is the code:
Can anyone please help me with this problem. Is it allowed to give application as field name in MS Access.
Many thanks,
Kiran Chapidi
This is not working:
Private Sub application_Click()
If application.Value = "5= others" Then
Me.application_txt.Visible = True
Else
Me.application_txt.Visible = False
End If
End Sub
This is working fine:
Private Sub Design_Click()
If Design.Value = "3= others" Then
Me.design_txt.Visible = True
Else
Me.design_txt.Visible = False
End If
End Sub

VBA code when refering a SubReport from a Main Report in Access

I am setting an instruction (VBA) in On Load Event on a report in MS Access.
When I open the report,the code works perfect.
But when i try to embeded the report as a subreport on a main report, the code doesnt work.
I think the problem is that I should be referering the field different(Me.Service1...), since I am trying to call the field now from a main report, but i havent found the right syntaxis.
This is the code i wanna embeed on my main report:
Private Sub Report_Load()
If Me.Service1 = "Scanmachine" Then
Me.Vessel.Visible = True
Me.Label400.Visible = True
Else
Me.Vessel.Visible = False
Me.Label400.Visible = False
End If
End Sub
Any suggestions?
Indeed, you need to change the relative reference of your sub report controls. Over the course of my Access database development work, I have used this Access MVPs resource, even bookmarked the webpage (though it uses forms, the same naming setup applies to reports).
Consider the following, adjusting names accordingly and run this on the main report's OnOpen() event:
Private Sub Report_Load()
If Me![subreportcontrolname].Report!Service1 = "Scanmachine" Then
Me![subreportcontrolname].Report!Vessel.Visible = True
Me![subreportcontrolname].Report!Label400.Visible = True
Else
Me![subreportcontrolname].Report!Vessel.Visible = False
Me![subreportcontrolname].Report!Label400.Visible = False
End If
End Sub

Make image visible or not visible based on multiple checkboxes

The following code turns an image on or off based on whether there are two checkboxes checked. The problem is as I add checkboxes only the last two work correctly. In the example below the image does not turn on and off if chk_Pipe1N and chkIn1 are both checked. However it works perfectly when chk_Pipe2N and chkIn2 are both checked. If I add chk_Pipe3N and chkIn3 it will work for this set, but set 1 and 2 no longer work. Any ideas why?
'NIn
If Me.chk_Pipe1N Or Me.chk_Pipe2N And Me.chkIn1 Or Me.chkIn2 Then
Me.imgNIN.Visible = True
Else
Me.imgNIN.Visible = False
End If
'NOut
If Me.chk_Pipe1N Or Me.chk_Pipe2N And Me.chkOut1 Or Me.chkOut2 Then
Me.imgNOut.Visible = True
Else
Me.imgNOut.Visible = False
End If
Simpler (adding #HansUp's comment):
Me.imgNIN.Visible = (Me.chk_Pipe1N Or Me.chk_Pipe2N) And _
(Me.chkIn1 Or Me.chkIn2)

Compile Error: Argument Not Optional | Access VBA

I have a form on Access where I have 3 ComboBoxes (Section, Rooms: White House, Rooms: Churchills). I need to have it so when 'White House' is selected from the 'Section' ComboBox, 'Rooms: Churchills will be Locked. And the opposite for 'Churchills'.
I have the code:
Private Sub Section_Change()
If Section.Value = "White House" Then
Rooms__White_House.Enabled = True
Rooms__Churchills.Enabled = False
Else: Section.Value = "Churchills"
Rooms__White_House.Enabled = False
Rooms__Churchills.Enabled = True
End If
End Sub
But when I test the form it throws the error:
Compile Error: Argument Not Optional
Any Help Appreciated. Thanks in Advance!
The problem is that Section is a reserved word. So the compiler doesn't recognise it as the name of your combobox. Just change the name of the combo to something else, e.g. cboSection, and your code will compile. (You naturally need to change your code to match the new name).
This link shows a list of names that you should avoid when working with Access http://allenbrowne.com/AppIssueBadWord.html
BTW, your line
Else: Section.Value = "Churchills"
seems a bit odd as it is setting the value of the combo. I'm guessing that you are meaning to comment what the value must be if you enter the Else section. If that's the case then you need to add the apostrophe in front of the comment, i.e.
Else: 'Section.Value = "Churchills"