Coding

M

Mavis

Hi All,

I have this below codes. In the last 4th line, (Me.Filter = "Status <>
'disposed'"), is there a way that i can allow user to select the "<>" and
'disposed" from a form. Which mean that i will have a form with a choice of
"<>" or "=", and the other status 'disposed", "In use", etc. the code will be
taken from the choices from the form.
Example: If the user select "=" and "In Use", then the code will become
Me.Filter = "Status = 'In Use'".


Private Sub Show_All_Records_Click()

'Button will display "Show All Records" when first load the form
'It will change to "Filter Records" once the button is click
If Show_All_Records.Caption = "Show All Records" Then
Show_All_Records.Caption = "Filter Records"

'All records will be display
Me.Filter = ""
Me.FilterOn = True

Else: Show_All_Records.Caption = "Show All Records"

'Record with Status does not equal to "disposed" will display
Me.Filter = "Status <> 'disposed'"
Me.FilterOn = True

End If

End Sub
 
A

AccessVandal via AccessMonster.com

If others have suggestion, you’re welcome to post here.

Yes, you can use the combo box, check box and Radio button or and
combinations of these.

You can use coding or just set it on the control’s value.

Status is a reserved word in Access, please rename it else you may encounter
problems in the future. If you can't, then use the square brackets like "
'All records will be display
Me.Filter = ""
Me.FilterOn = True

I can never see the reasons for the above code. I guess there must be one.

' here is what I would suggest, code can be in the checkbox afterupdate event
' or some where else
if me.checkbox1 = true then me.checkbox1.defaultvalue = " <> "

if me.checkbox2 = true then me.checkbox2.defaultvalue = " = "
'..so on…..

' as for the combobox, just create it using valuelist or from a table of the
control source.

'set the form filter
Me.Filter = "[Status] " & me.checkbox1.defaultvalue & " " & "'" & me.
combobox1 & "'"

Checkbox1 is your boolean operators
Combobox1 is your selected text.

or use case select like

' using the options groups afterupdate event
Select Case me.Frame1.value
Case 1 : me.Frame1.defaultvalue = " <> "
Case 2 : me.Frame1.defaultvalue = " = "
' so on…..
End Select

' so somewhere in your button event
Me.Filter = "[Status] " & me.frame1.defaultvalue & " " & "'" & me.combobox1 &
"'"

HTH
 
M

Mike Painter

Mavis said:
Hi All,

I have this below codes. In the last 4th line, (Me.Filter = "Status <>
'disposed'"), is there a way that i can allow user to select the "<>"
and 'disposed" from a form. Which mean that i will have a form with a
choice of "<>" or "=", and the other status 'disposed", "In use",
etc. the code will be taken from the choices from the form.
Example: If the user select "=" and "In Use", then the code will
become Me.Filter = "Status = 'In Use'".
Me.filter = "Status" & EqualNotEqual & "'" & InuseOrNot & "'"

EqualNotEqual and InuseOrNot could be a combobox or listbox.

You can also use the onclick event to pick a value.

Select Case EqualNotEqual
case "="
EqualNotEqual = "<>"
case "<>"
EqualNotEqual = "="
end select


This works well with up to three choices, after that the combo or listbox
is probably better.
 
M

Mavis

Hi All,

I am very new to access. Not very sure how to do what you have adviced.
I have the below code but still unable to get what i want.

In parameterFilter, there is "=" and "<>" for the user to select
In ParameterStatus, There is all the status for example "inactive", "In Use"
and etc

Private Sub Show_All_Records_Click()

'Button will display "Show All Records" when first load the form
'It will change to "Filter Records" once the button is click
If Show_All_Records.Caption = "Show All Records" Then
Show_All_Records.Caption = "Filter Records"
Me.parameterFilter.Visible = True
Me.ParameterStatus.Visible = True
Me.FilterParameter.Visible = True

'All records will be display
Me.Filter = ""
Me.FilterOn = True

Else: Show_All_Records.Caption = "Show All Records"

Me.parameterFilter.Visible = False
Me.ParameterStatus.Visible = False
Me.FilterParameter.Visible = False

'Record with Status
Me.Filter = "Status" & Me.parameterFilter & "'Me.ParameterStatus'"
Me.FilterOn = True

End If

End Sub

Please kindly help me to solve my problem.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top