Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Default value for Combo Boxes! Can it be done? Probably!

Status
Not open for further replies.

Rmck87

Programmer
Jul 14, 2003
182
0
0
US
Hey guys, i know there are things out in the forums similar to this question, but i havent found anything similar to what i need help with. And any help would be much appreciated.

Ok, i have an option group(sortbybox) on the same form as 5 combo boxes. Based on the option selected in sortbybox certain comboboxes will be available for selection. Then, based on selections chosen by the user in the combo boxes, other selections will be limited in other combo boxes. Like In one combo i have states, based on the state chosen, the slection of schools are limited to that state. And based on the school chosen, the selection of grades are limited, and so forth. I have all that done, but what i want now is to have Default values set whenever i load the form, and whenever someone selects a different option, or combo selection, limiting the combo selections too. What i did before i had to synchronize my combos was taht i set the 'Bound Column' to 0. And i wrote this code:

If sortbybox = 1 Then
Combo48 = ""
Combo50 = 0
Combo52 = 0
Combo60 = 0
Combo62 = 0
Me!Combo48.Enabled = False
Me!Combo50.Enabled = True
Me!Combo52.Enabled = True
Me!Combo60.Enabled = True
Me!Combo62.Enabled = True
ElseIf sortbybox = 2 Then
Combo48 = 0
Combo50 = ""
Combo52 = 0
Combo60 = 0
Combo62 = 0
Me!Combo48.Enabled = True
Me!Combo50.Enabled = False
Me!Combo52.Enabled = True
Me!Combo60.Enabled = True
Me!Combo62.Enabled = True
ElseIf sortbybox = 3 Then
Combo48 = 0
Combo50 = 0
Combo52 = ""
Combo60 = 0
Combo62 = 0
Me!Combo48.Enabled = True
Me!Combo50.Enabled = True
Me!Combo52.Enabled = False
Me!Combo60.Enabled = True
Me!Combo62.Enabled = True
Else
Combo48 = 0
Combo50 = 0
Combo52 = 0
Combo60 = ""
Combo62 = ""
Me!Combo48.Enabled = True
Me!Combo50.Enabled = True
Me!Combo52.Enabled = True
Me!Combo60.Enabled = False
Me!Combo62.Enabled = False
End If

This code was setting the default values to 0. and Enabling certain combos. But now that i am synchronizing the combos, i HAVE to set the 'Bound Columns' to 1. This poses a problem now. If i use the same code, i end up with '0' (zero's) in my combo boxes. I want the selections to be there, so that they are limited, and everything. Is there any way to do this? If so please let me know.

And some things, that should not have been forgotten, were lost.
 
You could try hiding the first column in each combo box using the ColumnWidth property ... like 0";1";1" ...

HTH

Greg


Boss quote from an office meeting: We're going to continue to have these meetings until we figure out why no work is getting done ...
 
all that does is makes the combo drop down selections invisible. it doesn't set a default.. Any ideas?

And some things, that should not have been forgotten, were lost.
 
Why not use the Default Value property of the combo box? Dunno why I didn't think of that in the first place.

Boss quote from an office meeting: We're going to continue to have these meetings until we figure out why no work is getting done ...
 
Well, i have thought of using that, but i dont know what i would put in there. It cannot be a constant variable. Because the defaults will be changing often.

And some things, that should not have been forgotten, were lost.
 
If the default value is always going to be the same for all the combo boxes, you could create a variable local to your function and initialize it's value:

Dim vDefault as variant

.... (code here) ...

Code:
If sortbybox = 1 Then
        Combo48 = ""
        Combo50 = vDefault
        Combo52 = vDefault
        Combo60 = vDefault
        Combo62 = vDefault
        Me!Combo48.Enabled = False
        Me!Combo50.Enabled = True
        Me!Combo52.Enabled = True
        Me!Combo60.Enabled = True
        Me!Combo62.Enabled = True
    ElseIf sortbybox = 2 Then
    ...
    End If

Something like that.

Something I've done in the past, and I think I'm still using it (for some strange reason), was create custom properties for the database and store some setup variables in there ... when the database starts, I was retrieving the values of these properties and storing them in global variables, which were then accessible throughout the code.

Hope I gave you an idea towards a solution ...

Greg



Boss quote from an office meeting: We're going to continue to have these meetings until we figure out why no work is getting done ...
 
Well, yes that would work. But, no my variables will never be all the same, they will be varying. Whenever the user selects something in the first combobox the next combobox will have different values, and the default will will be different for each selections. Sorry that this idea has not worked, but it was a good idea!

-Ryan

One Ring to Rule Them All, One Ring to Find Them, One Ring to Bring Them All, and in the Darkness Bind Them.
 
If the Comb_box data is from a file then use the

Default Value property to point to a record and field

eg.

Default value=DLookUp("mgtDOCTXT","MEMREG","mgtDOCNAME = 'MG01'")

you can easily maintain the default record "MG01" field value of file a General purpose Memory Register file
 
Defaulting the value of a combo box to the first element in the list (put this in the Default value property):

[ComboBoxName].[ItemData](0)

Whenever the selection is changed, requery the combo box.

Good luck

[pipe]
Daniel Vlas
Systems Consultant

 
I would suggest going to this site and looking at the January issue of this newsletter. There is a description of a similar problem which I found quite useful. The idea was to set the first combo box to a particular state, and then requery the database to fill the second combo box. I'm pretty sure this technique can be used for more than two combo boxes.

Lincoln
 
Here is how to do it:

Me!Combo48 = Me!Combo48.ItemData(0)
Me!Combo50 = Me!Combo50.ItemData(0)
Me!Combo52 = Me!Combo52.ItemData(0)
Me!Combo60 = Me!Combo60.ItemData(0)
Me!Combo62 = Me!Combo62.ItemData(0)

The main idea is that after requerying the combo boxes you have to actually set their value to the first available item (in each combo box).

That is not recommendable for bound combo boxes, as it would write to the corresponding record.


Good luck



[pipe]
Daniel Vlas
Systems Consultant

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top