Having two combo boxes bounded to a field of a table (1 Viewer)

emsadoon

Registered User.
Local time
Today, 06:01
Joined
Jun 6, 2013
Messages
83
I have two combo boxes containing integers on a form. How can I store the values of these combo boxes in a field of a table separating them by comma or semi colon?
 

gbnz

Registered User.
Local time
Today, 04:01
Joined
Mar 12, 2010
Messages
63
I am working under the assumption that the two combo boxes are unbound and that your form has the data field listed in its Record Source... this is how I would code it.

In the afterupdate of the second combo box
Code:
Private Sub cbo2_afterupdate()
    
    Me.FieldOfATable = Me.Cbo1 & "; " & Me.Cbo2

End Sub
Of course if there is no data in the first combo box your result will be a ; with data from the second combo box. You can place "If" statements in there to check for data in your Combo Boxes.
 

emsadoon

Registered User.
Local time
Today, 06:01
Joined
Jun 6, 2013
Messages
83
I greatly appreciate your help gbnz. I implemented your code and it woks perfectly. However, is there any way that when I go to a specific record, the values of the combo box gets updated to what they should be. Because right now, when I go to a new record, the values of the combo boxes stay either the same as the one I enetered previously or blank. Basically I want the default of the combo boxes to be the same as what we recorded.
 

gbnz

Registered User.
Local time
Today, 04:01
Joined
Mar 12, 2010
Messages
63
I greatly appreciate your help gbnz. I implemented your code and it woks perfectly. However, is there any way that when I go to a specific record, the values of the combo box gets updated to what they should be. Because right now, when I go to a new record, the values of the combo boxes stay either the same as the one I enetered previously or blank. Basically I want the default of the combo boxes to be the same as what we recorded.

To update a combo box's query you would use the requery function

Code:
Private Sub cbo2_afterupdate()
          
    Me.FieldOfATable = Me.Cbo1 & "; " & Me.Cbo2
    Me.Cbo1.Requery
    Me.Cbo2.Requery

End Sub
I hope this helps.
 

emsadoon

Registered User.
Local time
Today, 06:01
Joined
Jun 6, 2013
Messages
83
Thanks, but the combo boxes still stay unchanged. Just to let you know, my form is a split design form and when I click on any row of the spreadsheet view of the form, I can see them in filed boxes at the bottom except the combo boxes, which their values stays blank or the same as what I entered. Here is the code that I have:
PHP:
Private Sub Combo208_AfterUpdate()
CollectionTime = Me.Combo189 & ":" & Me.Combo208
Me.Refresh

End Sub

Private Sub Como208_afterupdate()

CollectionTime = Me.Combo189 & ":" & Me.Combo208
Me.Combo189.Requery
Me.Combo208.Requery
End Sub
 

Mihail

Registered User.
Local time
Today, 12:01
Joined
Jan 22, 2011
Messages
2,373
Yes it can be done by using the SPLIT function and a lot of effort to code after.
But, may I ask WHY you wish to store both values in a single field ?
Use two fields to store the value for each combo in one field and your troubles will disappear.
 

emsadoon

Registered User.
Local time
Today, 06:01
Joined
Jun 6, 2013
Messages
83
Yeah, I think it does not worth it. I needed two combo boxes to be used as hour and minute. I want to have 0 to 23 in hour box, and 0 to 59 in the minute box. But now, I think I should either use two diffrent boxes or use an input mask.
 

Pat Hartman

Super Moderator
Staff member
Local time
Today, 05:01
Joined
Feb 19, 2002
Messages
43,478
Use a field defined as datetime to store the value. In the Current event of the form, use something like the following:
Code:
Me.txtHour = IIf(Hour(Mydatefield) > 12, Mydatefield -12, Mydatefield))
Me.txtMinute = Minute(Mydatefield)

Notice I subtracted 12 when hour was greater than 12. That's because, the Hour() function assumes a 24 hour clock. You will need to handle this in your code when saving the data also.
 

Pat Hartman

Super Moderator
Staff member
Local time
Today, 05:01
Joined
Feb 19, 2002
Messages
43,478
If you want to use "military" time, then don't subtract 12. Most civilians make assumptions about time. If I schedule a meeting with you at 4 O'clock for example, you will assume I mean 4PM. But the military needs to be precise and eliminate assumptions that can lead to disaster and they would say 16:00 as the meeting time.
 

nanscombe

Registered User.
Local time
Today, 10:01
Joined
Nov 12, 2011
Messages
1,082
A lot of we Brits are used to the 24hr clock.

We're used to reading it from our public transport timetables. :D
 

Users who are viewing this thread

Top Bottom