0

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!

1
  • It always helps to tell us what line the compiler breaks on. It saves time, and often the problem can be determined by inspection. Commented Mar 22, 2015 at 0:35

1 Answer 1

1

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"
Sign up to request clarification or add additional context in comments.

1 Comment

Hello DeanOC, How are you today? I done what you said and it is now working. I have also bookmarked your link. Thanks for your help! I did mean to comment it yes, It has been one of those weeks haha. Thanks again man.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.