0

I'm making a search form for keyword searches. I have comboboxes with values ["And","Or","Not"], comboboxes with a list of field names, e.g. ["Title","Description",...] and textboxes associated with each combobox. I'm trying to create the sql query based on the values of the comboboxes and text box. To do that, I need to refer to the field name based on the value of the combobox. I'm trying solutions I've found searching, but I'm still getting the error: "Compile error: Sub or Function not defined". The debugger highlights "VHS_Metadata_Aug52014(field)" in yellow.

.....

bool_type = Me!Controls!dropBoolType2.value

field = Me!Controls!dropSearch2.value

value = Me!Controls!txtKeywords2.value

If (value) > 0 Then

    SQL_query_string = SQL_query_string & " " & bool_type & " " & VHS_Metadata_Aug52014(field) = " & value"

End If

.....

1
  • 1
    And what is VHS_Metadata_Aug52014? The syntax: VHS_Metadata_Aug52014() is that of a function. Commented Aug 6, 2014 at 20:34

1 Answer 1

1

I'd use dot notation instead. Using bangs like that doesn't let you use variables very easily. Try something like

Forms("formname").controls(foo).value

Where foo is the value from the combobox.

I'm not sure what VHS_Metadata_Aug52014 is though, if it's the name of the form you were trying to reference, you were partly there.

Sign up to request clarification or add additional context in comments.

1 Comment

Interestingly, I'm in the habit of using the ! because in the code editor in Access, when I type a "!", intellisense helps me find the control name, but not with ".". Makes no sense to me.

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.