HELP WITH REPORTS

G

Guest

So here is the deal. I'm a basic user of access, I know enough of the basic
to be dangerous. At work, I have to do alot of visit requests for employees
to visit gov. installations and military bases. For as long as I can
remember, I have had to hand type all of the names, ssns, dob, clearance
level for each person, can get tedious especially when I have 30 people on
one document. So I made a Access table with all of the stuff I need, made a
nice simple form to enter data for new people, and I made a simple querie to
extract the stuff I need and a nice report in the proper letter format that I
need. Now, comes the problem. whenever I run the report, that is based on the
query, it pulls all of the data into the report. I know how to make a subform
in my main for, add a list box to it and select the multi select property. I
just don't know how to get those names that I have selected in the list box
to my report. Can someone please help me. Thanks.

Jeff
Williamsburg, VA
 
J

John W. Vinson

. I know how to make a subform
in my main for, add a list box to it and select the multi select property. I
just don't know how to get those names that I have selected in the list box
to my report. Can someone please help me.

Here's some VBA code you can adapt.

Private Sub cmdProcess_Click()
' Comments : Update the AnimalCondition table based on the selections in
' the unbound multiselect listbox lstHealthIssues.
' Newly selected rows will be added to the table, newly
cleared
' rows will be deleted.
' Parameters: None
' Modified : 01/29/02 by JWV
'
' --------------------------------------------------
' Populate the AnimalCondition table with the selected issues
On Error GoTo PROC_ERR

Dim iItem As Integer
Dim lngCondition As Long
Dim db As DAO.Database
Dim rs As DAO.Recordset

' save the current record if it's not saved
If Me.Dirty = True Then
Me.Dirty = False
End If
Set db = CurrentDb
' Open a Recordset based on the table
Set rs = db.OpenRecordset("AnimalCondition", dbOpenDynaset)
With Me!lstHealthIssues
' Loop through all rows in the Listbox
For iItem = 0 To .ListCount - 1
lngCondition = .Column(0, iItem)
' Determine whether this AnimalID-HealthID combination is
currently
' in the table
rs.FindFirst "[AnimalID] = " & Me.AnimalID & " AND " _
& "[HealthIssueID] = " & lngCondition
If rs.NoMatch Then ' this item has not been added
If .Selected(iItem) Then
' add it
rs.AddNew
rs!AnimalID = Me.AnimalID
rs!HealthIssueID = lngCondition
rs.Update
End If ' if it wasn't selected, ignore it
Else
If Not .Selected(iItem) Then
' delete this record if it's been deselected
rs.Delete
End If ' if it was selected, leave it alone
End If
Next iItem
End With
rs.Close
Set rs = Nothing
Set db = Nothing
Me.subAnimalCondition.Requery

PROC_EXIT:
Exit Sub

PROC_ERR:
MsgBox "Error " & Err.Number & " in cmdProcess_Click:" _
& vbCrLf & Err.Description
Resume PROC_EXIT

End Sub



John W. Vinson [MVP]
 

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

Similar Threads

reports 6
Reports 2
Search by Combobox Criteria 7
Renaming Reports For Emailing 6
Annotating and expired date 3
Reports 2
Email Multiple Users 2
Reporting Groups 3

Top