Solved How to display text from 2 Combo Boxes selections? (1 Viewer)

bnefit

New member
Local time
Tomorrow, 03:14
Joined
Jul 28, 2020
Messages
23
Hi

I am new to Access and to the forum. I am trying to build a database and currently have a problem in Forms that require assistance.

I have created the following in Access:
Query: _Test & Tag
1595915465861.png


In Forms, I have created 2 Combo Boxes which I have labelled as Location (Combo33) and Description (Combo37). I have also created a Text Box labelled as Current Test Date (Text40).

1595915520037.png


For Combo33 (Location), I want to have a dropdown list of the various locations so I have set the Row Source as:
SELECT DISTINCT [_Test & Tag].Location FROM [_Test & Tag] ORDER BY [_Test & Tag].[Location];

For Combo37 (Description), the list of items will depends on the location so I have set the Row Source as:
SELECT [_Test & Tag].Description FROM [_Test & Tag] WHERE Combo33=[_Test & Tag]!Location ORDER BY [_Test & Tag].[Description];

For Text40 (Current Test Date), I would like to display the Test Date from _Test & Tag depending on the selection of Combo33 and Combo37. However, I am having trouble trying to get this to work.

I have tried to set the Control Source to DLookup(“[Test Date]”,”[_Test & Tag]”,”[Combo33]=” & Forms!Test & TagUpdate2!Location, “[Combo37]=” & Forms!Test & TagUpdate2!Description) but it didn't work.

Thanks for reading and any ideas/help would be greatly appreciated.
 

June7

AWF VIP
Local time
Today, 09:14
Joined
Mar 9, 2014
Messages
5,470
Try this.

Combo37 properties:

RowSource: SELECT [Description], [Test Date] FROM [_Test & Tag] WHERE [Location] = [Combo33] ORDER BY [Description];
ColumnCount: 2
ColumnWidths: 2";1"

Then expression in Text40 ControlSource: =Combo37.Column(1)

Otherwise, correct DLookup:
Code:
=DLookup("[Test Date]", "[_Test & Tag]", "[Location]='" & Combo33 & "' AND [Description]='" & Combo37 & "'")

Description is a reserved word and should not use reserved words as names. Also shouldn't use spaces and punctuation/special characters in naming convention.
 
Last edited:

arnelgp

..forever waiting... waiting for jellybean!
Local time
Tomorrow, 01:14
Joined
May 7, 2009
Messages
19,237
some of the records in the query has same Location + description, but different Tag No.
 

bnefit

New member
Local time
Tomorrow, 03:14
Joined
Jul 28, 2020
Messages
23
Try this.

Otherwise, correct DLookup:
Code:
=DLookup("[Test Date]", "[_Test & Tag]", "[Location]='" & Combo33 & "' AND [Description]='" & Combo37 & "'")

Description is a reserved word and should not use reserved words as names. Also shouldn't use spaces and punctuation/special characters in naming convention.

Hi June7

I've tried the corrected DLookup code and it worked! Thank you very much!

I will rename "Description" to something else and also remove all spacing and punctuation/special characters as you suggested. :)
 

Gasman

Enthusiastic Amateur
Local time
Today, 18:14
Joined
Sep 21, 2011
Messages
14,271
Why not give your controls some meaningful names? 6 months down the line, you are not going to remember what Combo33 is?

cboLocation
cboDescription
txtTestDate

Even for this question it would have already saved you some typing. :)
 

bnefit

New member
Local time
Tomorrow, 03:14
Joined
Jul 28, 2020
Messages
23
Hi Bob, apologies once again and thanks for the reminder. :)
 

June7

AWF VIP
Local time
Today, 09:14
Joined
Mar 9, 2014
Messages
5,470
Glad you have a working solution. However domain aggregate would be my last choice as they can slow performance. I would recommend other suggested option of including field in combobox RowSource and expression in textbox references combobox column.
 

bnefit

New member
Local time
Tomorrow, 03:14
Joined
Jul 28, 2020
Messages
23
Hi June7

Thanks for the additional info. I just tried the other option and the performance is indeed faster. (y)
 
Last edited:

Users who are viewing this thread

Top Bottom