Ussing Form Data Before The Table is Updated

C

charles.kendricks

I have a form which is used to input church visitor data. From this
form I want to be able to generate a welcome letter while still having
the input form open. In other words I want to put the visitor into the
database and generate the letter without closing the input form (which
updates the underlying table used for the visitor name and salutation
in the welcome letter). Here is the code I thought would work

Private Sub btnWelcomeLtr_Click()
On Error GoTo Err_btnWelcomeLtr_Click

Dim stDocName As String
Dim strCriteria As String
strCriteria = "[LastName]='" & Me![LastName] & "'" & " AND " &
"[Salutation]='" & Me![Salutation] & "'"
lngRecNum = Me![ID]

stDocName = "rptWelcomeLetter"
DoCmd.OpenReport stDocName, , , strCriteria
Debug.Print strCriteria

Exit_btnWelcomeLtr_Click:
Exit Sub

Err_btnWelcomeLtr_Click:
MsgBox Err.Description
Resume Exit_btnWelcomeLtr_Click

End Sub

I am only trying to include the Salutation and Last name in the letter
 
G

Guest

The WhereCondition parameter of the OpenReport method (your strCriteria)
passes a filter to the report. It's like the criteria part of a query. It
doesn't actually pass values to the report; it just tells the report to
filter its data based on those values.
It looks like your table has an autonumber column (Id) for its primary key.
This should be what you pass into the report:
strCriteria = "Id = " & Me.Id
This will limit the report to just the new record.

You probably want to save the record before generating the report. This is
the only way to allow the report to get the value from the table. In the
command button routine, put the following somwhere before you open the report:
If Me.Dirty Then
Me.Dirty = False
End If

Barry
 

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