Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Setting Query Criteria based on VBA 1

Status
Not open for further replies.

ablunk

Programmer
Feb 18, 2011
4
US
Ive scoured the boards for an application of what I'd like to do.. but i'm obviously missing something or going about it wrong..

So I have a list box on a form that has an indexed list of NAMES, that allows a selection of 1-4.. I also have a option button that, if selected, outputs all results..

The user then sets a date range.. this date part works..

The problem:

When they hit the "Run" button... it sets a TEXTBOX value based on their NAME selection.. So if they pick the first one, the text box will read "1" and so on... but if they select the option button it sets the TEXTBOX to "Like '*'"...

The query then uses said TEXTBOX to populate a subform of the query results.

*** I know this is a really nasty way to do this.. but Ive been out of the access world for a while..

Anyway, it works when they use the list box.. but when they select the option button.. it sets the textbox to the appropriate "Like '*'" but it doesnt translate to the query results.. leaving the subform blank.

I'd also like to be able to unenable the list box if the option button is selected.. Which situation (afterchange, click, etc..) would I put it on?

Thanks in advance.
 
post your code

HTH << MaZeWorX >> "I have not failed I have only found ten thousand ways that don't work
 
ON THE BUTTON CLICK:

If optAll.Value = True Then
Me.txtPrinter.Value = "Like '*'"
Else
Me.txtPrinter.Value = Me.cmbPrinter.Value
End If

DoCmd.Requery PrinterQuery
[Forms]![frmPrinterQuery]![subPrinter].Visible = True

End Sub


Query Criteria:
[Forms]![frmPrinterQuery]![txtPrinter]
 
1)
If optAll.Value = True Then
Me!txtPrinter = Null
Else
Me!txtPrinter = Me!cmbPrinter
End If

2)
Query Criteria:
=[Forms]![frmPrinterQuery]![txtPrinter] OR [Forms]![frmPrinterQuery]![txtPrinter] IS NULL

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
What is the control I have to put this under to disable the listbox when the button is activated?

if me.optAll.value = true then
cmbPrinter.enabled=false
else
cmbprinter.enabled=true
endif

Then you get a star my friend.. that first code worked like a champ.
 
In the AfterUpdate event procedure of optAll ?

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
hmm, wasnt working before.. but thank you sir.

Problem solved.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top