Combo box

billmark

Board Regular
Joined
Dec 11, 2011
Messages
59
Hi
I created a combo box in the form to select the record and export to excel (I created a button). Please advise how to make the combo box with one blank at the top of the list so that I select the blank, then all record can be exported to excel.

Regards
 

Paul Ked

Active Member
Joined
Jun 4, 2015
Messages
442
Why blank? Why not make your 1st item in the combo "Select All" and act on that?
 

billmark

Board Regular
Joined
Dec 11, 2011
Messages
59
I tried this in the Row Source 'Select clt.Field1 FROM Client UNION Select "(All)" FROM Client GROUP BY clt.Field1'. When I select ALL from the combo box, it gives me blank.
Please advise how to fix.
 

welshgasman

Well-known Member
Joined
May 25, 2013
Messages
696
I tend to use a union and 0 for All. Then test for 0. If 0, select everything, if not build the criteria then select
 

billmark

Board Regular
Joined
Dec 11, 2011
Messages
59
I tried this
Select “ALL” FROM Client UNION Select clt.Field1 FROM Client GROUP BY clt.Field1

and a prompt to ask me to Enter the parameter.

Please assist if I need to adjust in the properties table or advise the correct statement.

The table Client has 5 fields.
 

welshgasman

Well-known Member
Joined
May 25, 2013
Messages
696
Firstly, whilst you can have as many fields as you want in a combo, I try and stick with 2. The PK Autonumber and the field I want as the dexcription.

Code:
SELECT ID, Rank from Rank
UNION
Select 0 AS ID, "All" as Rank from Rank
Order by ID
Then check for non zero ID and filter/adjust accordingly.

HTH
 

Micron

Well-known Member
Joined
Jun 3, 2015
Messages
1,758
cross posted
 

stumac

Active Member
Joined
Jul 16, 2010
Messages
471
I think based on the information on the other post, the issue you have is you want the combo box to say ALL but have the query checking for Null. change it to check for 'ALL':

VBA Code:
[forms]![main]![cbofield1] or [forms]![main]![cbofield1] = "ALL"
basically the second part of the expression evaluates to true if the combo box has ALL in it therefore returning all records.
 

Forum statistics

Threads
1,081,415
Messages
5,358,533
Members
400,502
Latest member
price83

Some videos you may like

This Week's Hot Topics

  • VBA (Userform)
    Hi All, I just would like to know why my code isn't working. Here is my VBA code: [CODE=vba]Private Sub OKButton_Click() Dim i As Integer...
  • List box that changes fill color
    Hello, I have gone through so many pages trying to figure this out. I have a 2020 calendar that depending on the day needs to have a certain...
  • Remove duplicates and retain one. Cross-linked cases
    Hi all I ran out of google keywords to use and still couldn't find a reference how to achieve the results of a single count. It would be great if...
  • VBA Copy and Paste With Duplicates
    Hello All, I'm in need of some input. My VBA skills are sub-par at best. I've assembled this code from basic research and it works but is...
  • Macro
    is it possible for a macro to run if the active cell value is different to the value above it
  • IF DATE and TIME
    I currently use this to check if date has passed but i also need to set a time on it too. Is it possible? [CODE=vba]=IF(B:B>TODAY(),"Not...
Top