Search based on checkboxes

A

AlexG

Hi all!
Here's my question:

I have created 1 table (Clients) with 10 fields (ClientID, Name, Adress,
Phone etc...).
Next, there is a form (Clients) that allows me to fill data into the
relevant fields of the table (ClientID, Name, Adress, Phone etc...)

Just below these 10 fields, there are 5 check boxes. They are all
positioned under the text label "Client wished to contact via:" that allows
me to select one or more of the following check boxes "E-mail, Post, Tel,
Fax, Telex".

So far, so good..

The thing I would like to do is to create a form which will act as a search
form. Inside this new form, I want to be able to have the above mentioned 5
check boxes (Under the text label "Please click on the appropriate search
criteria") and to be able to select one, two or all 5 of them. Finally,
pressing the "Search now" button, a report should be generated with the
records-clients that have selected to be contacted via the selected
methods-check boxes.

Can anyone pls tell me which is the easier method to do this due to that I
am new using Access...

Sorry for the long description... Any guidance will be highly appreciated!

Tnx, AlexG
 
E

Evi

You might find that the GettingStarted newsgroup will be a good choice for
your questions.
Lets call your report "YourReport" and the unbound checkboxes in your form
Chk1, Chk2, Chk3 etc.
Click Properties, on the Data tab, choose False next to Default Value
Add button to your Form and let the wizard choose to Preview your report
Open the button's code page by going to Properties, Events and clicking next
to On Click.

Just under where it says 'Dim stDocName As String'
insert the following

Dim Crit As String
Dim MyLength As Long


If Me.chk1 = True Then
Crit = Crit & "([E-mail]= TRUE) AND "
End If

If Me.chk2 = True Then
Crit = Crit & "([Post]= TRUE) AND "
End If

If Me.chk3 = True Then
Crit = Crit & "([Tel]= True) AND "
End If

If Me.chk4 = True Then
Crit = Crit & "([Fax]= True) AND "
End If

If Me.chk5 = True Then
Crit = Crit & "([Telex]= True) AND "
End If


MyLength = Len(Crit) - 5

If MyLength <= 0 Then
Crit = ""
Else

Crit = Left(Crit, MyLength)
End If

DoCmd.OpenReport stDocName, acPreview, , Crit

End If
 
A

AlexG

Evi, tnx a lot for your assistance.
I have already posted the same question in the GettingStarted newsgroup..
Will be more careful next time and sorry for the double post...

Since you have provided me with some guidance, can you help me with the
"End If without block If" error that prompts me regarding the last End If?

DoCmd.OpenReport stDocName, acPreview, , Crit

End If

End Sub

Also, when moving to another record (pressing the new record button that
have created), the checkboxes do not alter their state. They remain as
checked as when I clicked on them in the previous record...

Thank you very much. Pls inform me if I should post this question in the
GettingStarted newsgroup...


Ο χÏήστης "Evi" έγγÏαψε:
 
E

Evi

Sorry, my bad. Delete that last End If. It was a typo.

Evi
AlexG said:
Evi, tnx a lot for your assistance.
I have already posted the same question in the GettingStarted newsgroup..
Will be more careful next time and sorry for the double post...

Since you have provided me with some guidance, can you help me with the
"End If without block If" error that prompts me regarding the last End If?

DoCmd.OpenReport stDocName, acPreview, , Crit

End If

End Sub

Also, when moving to another record (pressing the new record button that
have created), the checkboxes do not alter their state. They remain as
checked as when I clicked on them in the previous record...

Thank you very much. Pls inform me if I should post this question in the
GettingStarted newsgroup...


? ??????? "Evi" ???????:
You might find that the GettingStarted newsgroup will be a good choice for
your questions.
Lets call your report "YourReport" and the unbound checkboxes in your form
Chk1, Chk2, Chk3 etc.
Click Properties, on the Data tab, choose False next to Default Value
Add button to your Form and let the wizard choose to Preview your report
Open the button's code page by going to Properties, Events and clicking next
to On Click.

Just under where it says 'Dim stDocName As String'
insert the following

Dim Crit As String
Dim MyLength As Long


If Me.chk1 = True Then
Crit = Crit & "([E-mail]= TRUE) AND "
End If

If Me.chk2 = True Then
Crit = Crit & "([Post]= TRUE) AND "
End If

If Me.chk3 = True Then
Crit = Crit & "([Tel]= True) AND "
End If

If Me.chk4 = True Then
Crit = Crit & "([Fax]= True) AND "
End If

If Me.chk5 = True Then
Crit = Crit & "([Telex]= True) AND "
End If


MyLength = Len(Crit) - 5

If MyLength <= 0 Then
Crit = ""
Else

Crit = Left(Crit, MyLength)
End If

DoCmd.OpenReport stDocName, acPreview, , Crit

End If
 

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