PDA

View Full Version : Combobox problem finding record



Christofu
12-16-2008, 10:35 PM
I'm using a combo box that has two columns

ApptDate | ApptTime
dd/mm/yyyy | hh:nn:ss

The combobox has been set to search for corresponding record After Update. However it can't seem to succesfully search for both fields at once.

It first gave me this:
="[ApptDate] = " & "#" & Format([Screen].[ActiveControl],"dd/mm/yyyy") & "#"

But that just gave me the first record of that date regardless of what Time i had chosen.

Then i changed it to

="[ApptTime] = " & "#" & Format([Screen].[ActiveControl],"hh:nn:ss") & "#"

And alas, it just gave me the first record with that corresponding time regardless of the date.

So i put "And" in between them and now it doesnt produce any record. Am stuck. Could help please? Thanks!

OBP
12-17-2008, 04:30 AM
The simplest solution is to have a dummy field on your table that combines the Date & Time, then your Combo can use that field to do what you want.
The combining of the 2 fields can be achieved in a Query or on the Form using VBA. The field does not have to be visible.

CreganTur
12-17-2008, 06:19 AM
There's something you may not be aware of when it comes to working with comboboxes. When you refernece the object's value you will always get the value of the first column only. You'll need to specifically reference the column you want if you want anything other than the first column value. You can do this using the .columns method.

Christofu
12-19-2008, 06:35 AM
Sorry for the late response. I've been looking around abit and still really figure out how to apply the .columns code. Could you please elaborate on it or link me? I know its simple but i still haven't a clue. Thanks

CreganTur
12-19-2008, 08:18 AM
Not a problem:
ObjectName.Column(1)
Replace ObjectName with the name of your combobox. Within the parentheses of the .Column method you put in the index of the column whose data you want to pull. All indexes in Access are zero based, so .Column(0) will pull the first column (the value of which is pulled when you reference the combobox's value).

So, .Columns(1) would pull the value of the 2nd column.

HTH:thumb

Christofu
12-21-2008, 08:19 AM
Ahkay thanks! I presume this goes into a query of some sort?I'll give it a go