That did get me farther, now I get the message box, but it still isn't
appending. Could it have anything to do with the fact that I'm getting
the
project# from the previous form (=Forms!frmAddQuote!ProjectID as
control
source)?
Thanks,
Deb
:
You have an End If at the very end.
It needs to be further up, so delete that line.
Immediately below the DoCmd.OpenReport line, add:
Else
MsgBox "No project number to add."
End If
Until you get this working, you may also want to comment out the error
handler on line 2 by adding a single quote:
'On Error Goto ...
I apologize for taking so long to get back to this Allen, I got
pulled
into
another project.
So here's my entire code for the on click event of the form and it
doesn't
work. Perhaps I misunderstood something in the code as I used pieces
and
parts from your example. When I say it doesn't work, nothing
happens,
no
message, no update, nothing. Any suggestions?
Private Sub cmdPreview_Click()
On Error GoTo Err_Handler
Dim varItem As Variant
Dim strWhere As String
Dim strDescrip As String
Dim lngLen As Long
Dim strDelim As String
Dim strDoc As String
Dim strSql As String
Dim lngID As Long
strDoc = "rptQuote"
With Me.lstBidders
For Each varItem In .ItemsSelected
If Not IsNull(varItem) Then
strWhere = strWhere & strDelim & .ItemData(varItem) &
strDelim & ","
strDescrip = strDescrip & """" & .Column(1, varItem)
&
""",
"
End If
Next
End With
lngLen = Len(strWhere) - 1
If lngLen > 0 Then
strWhere = "[ContractorID] IN (" & Left$(strWhere, lngLen) &
")"
lngLen = Len(strDescrip) - 2
If lngLen > 0 Then
strDescrip = "Bidders: " & Left$(strDescrip, lngLen)
End If
End If
If CurrentProject.AllReports(strDoc).IsLoaded Then
DoCmd.Close acReport, strDoc
End If
If Me.NewRecord Then
With Me.RecordsetClone
.AddNew
!ProjectID = Me.ProjectID
!MailingDate = Date
.Update
.Bookmark = .LastModified
lngID = !ProjectID
End With
If Me.[frmQuoteBidders].Form.RecordsetClone.RecordCount >
0
Then
strSql = "INSERT INTO [tblMailingDetail] ( MailingID,
ContractorID ) " & _
"SELECT " & lngID & " AS MailingID,
tblContractors.ContractorID " & _
"FROM [tblContractors, tblProjects] INNER JOIN
tblProjectDetails ON tblProjects.ProjectID = " &
tblProjectDetails.ProjectID
& ";"
DBEngine(0)(0).Execute strSql, dbFailOnError
End If
DoCmd.OpenReport strDoc, acViewPreview, WhereCondition:=strWhere,
OpenArgs:=strDescrip
Exit_Handler:
Exit Sub
Err_Handler:
If Err.Number <> 2501 Then
MsgBox "Error " & Err.Number & " - " & Err.Description, ,
"cmdPreview_Click"
End If
Resume Exit_Handler
End If
End Sub
Thanks,
Deb
:
That's right: if the form is unbound, you can skip the part that
check
if
it
is dirty, since an unbound form can't be dirty.
You can still use the approach of creating the Mailing record, and
then
storing the customers in the mailing.
--
Allen Browne - Microsoft MVP. Perth, Western Australia
Reply to group, rather than allenbrowne at mvps dot org.
Thanks. I tried the add and execute code (modified of course with
my
field
names, tables, etc.) and it didn't work. So I came up with a
couple
of
different reasons that may have happened:
1. The ever present, maybe I screwed something up
2. The form I'm using to select customers is a pop up (not a
subform)
with
a
listbox and a command button, so I can't really use me.dirty can
I,
because
I'm not really making changes and there is no record to copy from
this
form.... right?
Deb
:
To do that you need to store that info.
2 tables:
a) Mailing table, with fields:
MailingID AutoNumber primary key
MailingDate Date/Time when you sent this
QuoteID Number relates to Quote.QuoteID
Descrip Text optional description of
mailing
b) MailingDetail table, with fields:
MailingID Number relates to
Mailing.MailingID
CustomerID Number relates to Customer.CustomerID
Now, the query you created last time: turn it into an Append
query
(Append
on Query menu, in query design.) Access asks which table to
append
to:
answer MailingDetail. Type this into a fresh column in the Field
row:
MailingID: 99
and indicate this goes to the MailingID column.
Switch the query to SQL View (View menu.)
There's an example of the SQL statement you need to execute.
Now you will write some code to OpenRecordset on the Mailing
Table,
AddNew
and Update, and get the new MailingID number. You will then
create
a
SQL
string to Execute, adding the new MailingID number into the
string
in
place
of the 99.
If the Execute idea is new, here's an example:
http://allenbrowne.com/ser-60.html
or here's another that uses AddNew and then Execute:
http://allenbrowne.com/ser-57.html
message
Thank you Allen, as usual, the perfect solution
. One more
question.
is
there a way to track which customers I sent the quote to
(which
people
I
selected from the list box) so I can pull reports later on if
needed?
Deb
:
One approach would be to create a query that uses both tables
(the
people
you send to, and the quotes), but without any line joining
them
in
the
upper
pane of query design. This gives you every possible
combination
of
the
2.
Create a report based on this query, laid out with the
person's
names
at
the
top, and the quote underneath. Use the Sorting And Grouping
dialog
to
create
a group header on each QuoteID, and set the properties of the
QuoteID
header
so each quote starts on a new page.
Create a form where the user selects the quote number,
chooses
the
people
in
the multi-select list box, and clicks a button to print them.
The
Click
event procedure of the command button uses OpenReport with a
WhereCondition
so that it prints the right quote for the right people.
For an example of how to build the WhereCondition string,
see:
Use a multi-select list box to filter a report
at:
http://allenbrowne.com/ser-50.html
You will also need to add to the end of that string so it
prints
just
the
one quote. Something like this:
strWhere = strWhere & " AND (QuoteID = " & Me.[QuoteID]
message
Hi, and thanks for any help you can offer, I'm stumped. I'm
working
on
a
quotation database. I need the ability to enter a quote and
send
it
to
several people. I have the quote form established.
After entering the quote you click a button and a pop up
form
comes
up.
On
the pop up, you choose which customers to send the quote to
(multi
select
list box) and click another button to preview or print the
actual
quote.
Here's where I'm stumped. I can't figure out how to
customize
the
quote
for
the people I chose from the list box (i.e. I would like
their