How do I show a record as selected?

G

Guest

I have a need to show a record as selected and take action
against it.
I am displaying multiple records on a form. I would
like to select a few at random, Is it possible to
show some records as selected on screen? How can it be
done?

Thank you
 
R

Rick B

You would need to add a checkbox to your table and alow the user to check it
for the desired records. Then, they could click a button to perform some
task. After the task is complete, your code should uncheck the items.

Rick B
 
G

Guest

Rick,

I don't want to write to the database, just when the form
opens up, user should select certain records could be
by checking a box and then click on a button to do the
task, when the form closes, it should initialize check
box.

Thank you
 
A

Albert D. Kallal

If you can display the results as a list box, then that would allow
multi-selecting.

However, if you MUST use records, and they are bound to a form, then you can
simply use a collection.

Just put the following function in the forms module code

Option Compare Database
Option Explicit

Dim colCheckBox As New Collection


Public Function IsChecked(vID As Variant) As Boolean

Dim lngID As Long

IsChecked = False

On Error GoTo exit1

lngID = colCheckBox(CStr(vID))
If lngID <> 0 Then
IsChecked = True
End If

exit1:

End Function


Now, place a check box contorl on your form, and make the souce of hte check
box:

=IsChecked([id])

(we are assuming a key id of "id" here).

You then place a buttion be side the check box (or, even bettrer place the
buttion ON TOP OF THE check box, and make the buttion TRRANSPARNT.

The code for the buttion can then:

Private Sub Command13_Click()


If IsChecked(Me.ContactID) = False Then
colCheckBox.Add CLng(Me.ContactID), CStr(Me.ContactID)
Else
colCheckBox.Remove (CStr(Me.ContactID))
End If
Me.Check11.Requery

End Sub

At this point, you are free to navagbe to as many reocrds as you want, and
check them off.

You then can access the collection of checked records like:

Dim i As Integer
Dim strB As String

For i = 1 To colCheckBox.Count
If strB <> "" Then
strB = strB & ","
End If
strB = strB & colCheckBox(i)

Next i

MsgBox "selected = " & strB
 

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