Set ComboBox Default Value

berg

Registered User.
Local time
Yesterday, 23:28
Joined
Nov 23, 2012
Messages
15
Alright - so I need to know if what I want to do is even possible or not.

I have a form with a ComboBox. The ComboBox is populated with information from a table. Currently, we are not collecting the information for this ComboBox - so I want the default value of the ComboBox to be "N/A" (which is one of the options from the table). Once it is set to this value, I want to hide the ComboBox so that the users do not even have to see it, and the record will populate with "N/A". The reason for keeping the ComboBox is that we will be collecting this information in the future, so then it just has to be set to visible and the users can select a value as needed.

I have tried setting the default value in the ComboBox every way I can come up with. But no matter what, when I open the form the ComboBox is blank. The form is calling information from other tables, so I wonder if this is a problem with it not be a new record (I know there is some sort of issue where default values only appear for new records), but the information in the ComboBox is new and is being saved as a new record in a table, so I'm not sure why I'd be having this issue.

If anyone could let me know if what I want to do is even possible, that would be great. And then maybe some tips about how to hardwire my ComboBox.

Thanks!
 
One of the combox properties is "Default Value." Check it out.
 
Thanks.

But as I said, I've tried setting the default value every way I can think of. Of course the first thing I tried was the default value property. But everytime I open the form the ComboBox is still blank.
 
breg, just to make things clear, could you provide the following information.. Column Count, Bound Column, Row Source (exactly as it is).. The record "N/A" as it appears in the table (if it has an ID with the ID as well)

And then maybe some tips about how to hardwire my ComboBox.
Hard wire ComboBox???
 
Column Count = 2
Bound Column = 1
Row Source = tbl_Location

"N/A" has Location_Id = 11 (column 1), Location = "N/A" (column 2)

Sorry, hardwire might not be the right word. Obviously I'm not super experienced with MS Access. I just mean that I want to force it to set to N/A and not have the users edit it.

Thanks in advance for any advice.
 
Okay.. Put this as your Row Source..
Code:
SELECT Location_Id, Location FROM tbl_Location ORDER BY Location;
and in the default value put 11..

If you do not wish the users edit the ComboBox if it is N/A then you have to use the Form Current property to see what value and the set the Enabled to be false..
Code:
Private Sub Form_Current()
    If Me.[COLOR=Blue]comboBoxName[/COLOR] = 11 Then 
        Me.[COLOR=Blue]comboBoxName[/COLOR].Enabled = False
    Else
        Me.[COLOR=Blue]comboBoxName[/COLOR].Enabled = True
    End If
End Sub
Blue bits need to match your combo box name..
 
Last edited:
Thanks a lot!

I set it up as you suggested, but now upon opening the form I am getting a message box "Enter Parameter Value" - Location.
 
Hmmm... Location is the name of the field in the table right??? Try changing the code to..
Code:
SELECT [tbl_Location].[Location_Id], [tbl_Location].[Location] FROM tbl_Location ORDER BY [tbl_Location].[Location];
However there is a downside to this.. as in; the user will not be able to change the value.. If you wish to allow user the opportunity to edit values for new records then you have to add a condition to the above Form current code,
Code:
:
    If Not Me.NewRecord And Me.[COLOR=Blue]comboBoxName[/COLOR] = 11 Then
:
 
Ok, this time I no longer get the message box, but the combo box is still blank.
 
Thats bizarre, It works fine for me..

Can you just take a quick snapshot of the Property sheet(Data tab) for the combo box??
 
Here you go:
 

Attachments

  • Snap1.jpg
    Snap1.jpg
    24.2 KB · Views: 146
Check the row source, it probably contains a filter.
 
Hi berg,
sometimes I had this kind of Problems normally I don't set the value from the combo box in the form, i always set it from the table designer on the properties of the field, did you try that?
 
Still having this problem. Any other ideas?
 
One question berg
Are you setting the form to view as form view or as datasheet view?
 
Ok then for sure you have button in your form to add new record then you can add this line to your button code at the end of the procedure
Me.YourComboBoxName = "n/a"

Then go back on your form and add this line on your on current form event
If IsNull ([AnyMaincomboName]) then
Me.YourComboBoxName.Visible = True
Else
Me.YourComboBoxName.Visible= False
End If
If you can attach a sample of your database then maybe I can code it for you it would be much easy
 
Thanks Khodr - I appreciate your patience with me.

I see what you are saying. Once I get the default value to display properly in the ComboBox I am not worried about hiding it with the Visible property - I've managed to do that much.

But now we are getting back to the reason I posted this thread in the first place. I have tried setting both Me.cboLocation = 11 and Me.cboLocation = "n/a" into my procedure and the ComboBox is still blank when the record opens.

I just can't get the default value to display for the life of me.
 
Berg I will keep you company until you solve it
Would you please upload the table and the form in separate database here I will fix it up and attach it back to and explain it
 
I solved this for anyone who is interested....

I just used:
If cboLocation.ListIndex = -1 Then
cboLocation = 11
....

And then I hid the combobox and it works perfectly.
 

Users who are viewing this thread

Back
Top Bottom