Runtime Error 13 with Subform

Wirewalker

Registered User.
Local time
Today, 07:26
Joined
Mar 6, 2010
Messages
20
Hi,

I am writing the code for a database search form and have included an IF statement that is meant to check the value of an option button on a subform. Unfortunately I am encountering an "Type mismatch" runtime error 13 on the first line of the IF statement when attempting to execute. My code has this structure:

Me.Subform.SetFocus
If Me.Subform!OptionBtn.Value = True Then
[Change Variable Values]
End If

I have attempted to adapt the solutions for similar problems suggested on this forum to no avail. Any help would be greatly appreciated.
 
Personally i would drop the me and the value qualifier. Generally they are not needed.
(I am not sure, but it may even be incorrect ot use them in some cases??)


so not

If Me.Subform!OptionBtn.Value = True Then

but just

subform!optionbtn = true


when you get the form reference sorted, as vbainet pointed out you will probably find it should be a reference like this from the parent of the subform.

subform.form!optionbtn = true
 
Thank you for your replies, however I am given a Runtime 438 "Object does not support this property or method" error when attempting:

If Me!Subform.Form!OptionBtn.Value = True

I have also tried Me!SubForm.SetFocus above it, same error.
 
Last edited:
Of course I did that's why I tried Me!Subform.Form!OptionBtn.Value = True.
That's what I understood form the directions below "To refer to a control property, like Enabled" .
 
Last edited:
Where are you putting this code, on the subform or on your main form or on the option "button"?

Also tell me the name of the event you put the code?
 
I have just edited my last two replies to include OptionBtn. It seems I omitted that when I replied but I assure you it is included in the code and the runtime error still stands in the way.
 
Our posts must have crossed each other. I need to establish some things and those things are on my last post.
 
The code is in the main form and it is part of a function that is called when the search button is clicked, so the event is SearchBtn_Click(). The function checks the values typed in text boxes and is supposed to also check the option buttons selected on a subform but that's where the problem is.
 
This is the right way:
Code:
Me!CatList.Form!OptionBtn.Value

It sounds like you're not doing things correctly to get your desired result. Maybe you could explain exactly what you want to do and we could advise of a better way? A screenshot of your form would also help.
 
Attached is a screenshot of my form. It is meant to narrow down search results from a table of company contacts on the subdatasheet (blurred out as I cannot release that information) based on a user's input. The text boxes work fine, a user can find a contact based on their name, city, etc. However I also want to enable them to find a contact based on what category they belong to by selecting one or more categories from the subform to the right of the text boxes.
 

Attachments

  • Form.jpg
    Form.jpg
    96.3 KB · Views: 107
My first advise would be to get rid of the subform in which the option buttons sit and use a combo box or list box. You then set the Row Source of the control to the table from which those values are gotten. That way you don't have to reference a subform when trying to get what category is selected. How do you feel about that?
 
That's what I initially wanted to do. The problem is the category names are column names in the contacts table with Yes/No row values. This is because one contact can fall under several categories. As far as using a list box is concerned I could not find a way displaying these column names in the list box. I could, however make a table with the category names to use as the list box's row source but I also could not find a way to link the selected categories to their columns.
 
Getting the data to be displayed on the combo box or list box wouldn't be a problem. That can easily be done. You mentioned that one contact could fall under several cantegories, in that case does your current option box allow you to select multiple categories?

With a list box you can select multiple categories.
 
Indeed, it does. However, the problem I had with it was getting it to display the category names in a way that I could write the code that checks the value in the category column based on the user's selection.
 
the clue is probably in the name

what type of control is OPTIONBTN - is it a command button? - so you cant make it true or false!!
 
Are the values present in a particular table? Or did you type in the values for each of the option button's caption?
 

Users who are viewing this thread

Back
Top Bottom