I have a form in a MS Access 2003 database.
Each time I get a donation, I'm supposed to hit the button that says "Create Receipt". After that, I'm supposed to hit the button that says "Print Receipt" and it's supposed to give me a receipt of the most recent donation(s) i.e. of donations that were not yet receipted.
The "create Receipt" button and script is working well. However when I "print Receipt", instead of it printing the most recent donation, it prints the first receipt for that donor.
Here is the script on the form. I know nothing about programming so please give me the instructions in plain english. - Option Compare Database
-
Option Explicit
- Private Sub btn1_Click()
-
-
Dim sql1 As String
-
Dim sql2 As String
-
Dim sql3 As String
-
-
-
Dim rst1 As DAO.Recordset
-
Dim rst2 As DAO.Recordset
-
Dim rst3 As DAO.Recordset
-
Dim varnewid As Integer
-
-
-
-
-
-
sql1 = "SELECT * FROM Donations LEFT JOIN Receipts ON Donations.Receipt = Receipts.ID WHERE Donations.Donor = " & Nz(Form_frmDonations2.cbx1) & " AND Receipts.ID Is Null"
-
sql2 = "SELECT * from RECEIPTS"
-
sql3 = "Select * from DONATIONS WHERE Donations.Donor = " & Nz(Form_frmDonations2.cbx1) & " and (Donations.Receipt = 0 or Donations.Receipt is null) "
-
-
-
-
Set rst1 = CurrentDb.OpenRecordset(sql1)
-
Set rst2 = CurrentDb.OpenRecordset(sql2)
-
Set rst3 = CurrentDb.OpenRecordset(sql3)
-
-
-
If (rst1.RecordCount > 0) Then
-
rst1.MoveLast
-
MsgBox (rst1.RecordCount & " Donations will be assigned a new receipt")
-
-
With rst2
-
.AddNew
-
.Fields("timestamp") = Now()
-
.Update
-
.MoveLast
-
-
varnewid = .Fields("ID")
-
-
End With
-
-
-
With rst3
-
Do While Not .EOF
-
.Edit
-
.Fields("Receipt") = varnewid
-
.Update
-
.MoveNext
-
Loop
-
End With
-
-
Else
-
-
MsgBox ("There are no donations available")
-
End If
-
-
-
-
rst1.Close
-
rst2.Close
-
rst3.Close
-
-
Form_frmDonations2.subform2.Requery
-
-
-
End Sub
- Private Sub cbx1_AfterUpdate()
-
Form_frmDonations2.subform2.Requery
-
-
End Sub
- Private Sub btnprintpreview2_Click()
-
On Error GoTo Err_btnprintpreview2_Click
-
-
Dim stDocName As String
-
-
stDocName = "rptDonations"
-
DoCmd.OpenReport stDocName, acPreview
-
-
Exit_btnprintpreview2_Click:
-
Exit Sub
-
-
Err_btnprintpreview2_Click:
-
MsgBox Err.Description
-
Resume Exit_btnprintpreview2_Click
-
-
End Sub
- Private Sub btnexportword2_Click()
-
On Error GoTo Err_btnexportword2_Click
-
-
Dim stDocName As String
-
-
stDocName = "mcrExportWord"
-
DoCmd.RunMacro stDocName
-
-
Exit_btnexportword2_Click:
-
Exit Sub
-
-
Err_btnexportword2_Click:
-
MsgBox Err.Description
-
Resume Exit_btnexportword2_Click
-
-
End Sub
- Private Sub btnprintreceipt_Click()
-
On Error GoTo Err_btnprintreceipt_Click
-
-
Dim stDocName As String
-
-
stDocName = "rptDonations2"
-
DoCmd.OpenReport stDocName, acPreview
-
-
Exit_btnprintreceipt_Click:
-
Exit Sub
-
-
Err_btnprintreceipt_Click:
-
MsgBox Err.Description
-
Resume Exit_btnprintreceipt_Click
-
-
End Sub
- Private Sub btnexportword_Click()
-
On Error GoTo Err_btnexportword_Click
-
-
Dim stDocName As String
-
-
stDocName = "mcrExportWord"
-
DoCmd.RunMacro stDocName
-
-
Exit_btnexportword_Click:
-
Exit Sub
-
-
Err_btnexportword_Click:
-
MsgBox Err.Description
-
Resume Exit_btnexportword_Click
-
-
End Sub
- Private Sub btnopendoners_Click()
-
On Error GoTo Err_btnopendoners_Click
-
-
Dim stDocName As String
-
Dim stLinkCriteria As String
-
-
stDocName = "Doners"
-
DoCmd.OpenForm stDocName, , , stLinkCriteria
-
-
-
Form_Doners.Filter = "Doners.ID = " & Me.cbx1 & ""
-
Form_Doners.FilterOn = True
-
-
-
Exit_btnopendoners_Click:
-
Exit Sub
-
-
Err_btnopendoners_Click:
-
MsgBox Err.Description
-
Resume Exit_btnopendoners_Click
-
-
End Sub
- Private Sub btnexport2word_Click()
-
On Error GoTo Err_btnexport2word_Click
-
-
Call wordreceipts
-
-
Exit_btnexport2word_Click:
-
Exit Sub
-
-
Err_btnexport2word_Click:
-
MsgBox Err.Description
-
Resume Exit_btnexport2word_Click
-
-
End Sub
- Private Sub Command15_Click()
-
On Error GoTo Err_Command15_Click
-
-
-
Screen.PreviousControl.SetFocus
-
DoCmd.DoMenuItem acFormBar, acEditMenu, 10, , acMenuVer70
-
-
Exit_Command15_Click:
-
Exit Sub
-
-
Err_Command15_Click:
-
MsgBox Err.Description
-
Resume Exit_Command15_Click
-
-
End Sub
- Private Sub Command16_Click()
-
On Error GoTo Err_Command16_Click
-
-
-
DoCmd.GoToRecord , , acFirst
-
-
Exit_Command16_Click:
-
Exit Sub
-
-
Err_Command16_Click:
-
MsgBox Err.Description
-
Resume Exit_Command16_Click
-
-
End Sub
In the picture you attached, it shows that the first record is selected in the subform.
Please try selecting the last record in the subform and then click on your print receipt button.
This portion of the SQL - ((Donations.Receipt)
-
=[Forms]![frmDonations2]![subform2].[Form]![Receipt]
is looking at the current value of the [Receipt] field in the subform; thus, when you have the first record selected, the first record is the receipt (looks like #14? and the last record a #34?????) that should be reported...
8 1519
If it's the report that is incorrect, then we need to know what the report's source is. Not just the code that opens the report.
The report looks good, but has the wrong record. Where can I find the code that will dictate which record is used for the report?
zmbd 5,501
Expert Mod 4TB
Press [F11] so that the Access Object Navigation Pane (AONP) is open.
You will need to locate the report group and "rptDonations2."
You will now need to open "rptDonations2" in design view. The easiest method is to right-click on the report in the AONP, when the popup menu opens, select the "Design View" option.
When the report opens, right-click on the report, anywhere except a control, when the popup menu opens, select the "Report Properties" option.
Select the Data Tab. You should see the following:
Record Source :: name of query/table and or some code.
Filter :: might be blank or may have information
Filter On Load :: default is "No"
Order BY :: might be blank or may have information
Order BY On Load :: default is "No"
Allow Filters :: default is "Yes"
We will need all of that information.
Additionally, take note of the "Record Source" value. If this is a query (most likely) we will need the SQL behind this query - to get this is much like what we did for the report...
Find the query name shown in the "Record Source" ine the ANOP.
Right-Click... select "Design View"
Once the pretty GUI for query design opens:
In the top section there is an area where the tables/queries are shown in boxes - right click on a BLANK area - not in the grided section.
In the popup menu, "SQL View"
<Ctrl<A>>, <Ctrl<C>> (windows select all, copy).
Now to post this code/sql, make sure that you click on the [CODE/] button in the formatting bar FIRST. This will insert a pair of code tags, [code]..............[/code], you will (replace the dots :) ) use the standard windows paste (<Ctrl<V>>) to place the sql between the tags.
We may also need to open the form in "Design View" to get the control name that is generating your receipt...
Hello and thank you for helping out.
The report properties:
Record source: qryDonationReport
filter - blank
filter on load: no
order by: blank
Order by on load: no There is no line for Allow filters
The sql from the qryDonationReport is below - SELECT Doners.ID, Doners.Title
-
, Doners.[First Name], Doners.[Last Name]
-
, Doners.Address, Doners.City
-
, Doners.Province, Doners.[Postal Code]
-
, Donations.ID, Donations.Amount
-
, Donations.Cheque, Donations.Date
-
, Donations.Year, Donations.Details
-
, Donations.Receipt, Receipts.timestamp
-
FROM Receipts
-
RIGHT JOIN (Doners
-
RIGHT JOIN Donations
-
ON Doners.ID = Donations.Donor)
-
ON Receipts.ID = Donations.Receipt
-
WHERE (
-
(
-
(Doners.ID)=[Forms]![frmDonations2]![cbx1])
-
AND
-
((Donations.Receipt)
-
=[Forms]![frmDonations2]![subform2].[Form]![Receipt]
-
)
-
);
-
zmbd 5,501
Expert Mod 4TB
In the picture you attached, it shows that the first record is selected in the subform.
Please try selecting the last record in the subform and then click on your print receipt button.
This portion of the SQL - ((Donations.Receipt)
-
=[Forms]![frmDonations2]![subform2].[Form]![Receipt]
is looking at the current value of the [Receipt] field in the subform; thus, when you have the first record selected, the first record is the receipt (looks like #14? and the last record a #34?????) that should be reported...
Wow, all I can say is thank you thank you thank you. Am I really that stupid?! I've been braking my head on this for a couple of weeks now. You're the best.
Eli
zmbd 5,501
Expert Mod 4TB
No, You are not that stupid. The programmer should have provided better user feedback.
The form should have indicated that you should select the record...
Or
Should have indicated which record the receipt would be printed for...
The first via a simple lable control saying.. hey tigger, select the donation you need a receipt for...
The second has a dozen ways to solve; however, they all have one thing in common, there would be a control on the form that indicates which receipt will be printed.
I'm a Chemist by trade (think lab not pharm); however, we had to take quite a bit of the compsci for my program. The compsci prof was a killer on user feedback. You could get an 100% on the codeing and still fail the assignment because the user feedback failed.
Sign in to post your reply or Sign up for a free account.
Similar topics
by: |:::. George .::::| |
last post by:
Hi,
When I put the first javascript, it works fine. As soon as I put the
second one, the effect stops on both and you can't see any pictures.
This is the script I'm using. {How can I have this...
|
by: Throw |
last post by:
G'day everyone!
I would like to design typing tutor exercises for Afrikaans (and other
languages possibly). This is for a GPL project. For this, I need a
script that can extract words from a...
|
by: D |
last post by:
Hello all...I have an issue with one of my java script functions that
I'm hoping someone can easily help with. I have a web based application
that we use to create/sign up for overtime. When we...
|
by: imatts |
last post by:
Hi can anyone help with this little problem. I have a simple script to
swap between two divs on a page. It works perfectly in Firefox & Safari
& Opera. It fails in IE 6 giving Object Required error...
|
by: hrakbari |
last post by:
hi vijay
im looking for script to Send SMS from Meteor.ie site,
but the problem is that body of text has to copy content of text file and also the reciptioner mobile is saved in a text file also....
|
by: deppeler |
last post by:
Can someone look at this for me:
I am trying to set up a script to edit an item in a flat file DB but I don't seem to be getting the data to the Photoedit script. It seems to be reading the 1st line...
|
by: Kesavan |
last post by:
I need a function such that it returns a string holding the contents
of function in other php file..,
...
|
by: dbase |
last post by:
Hey guys, I'm new here. Sorry if this is not the correct forum for my question.
I run a blog that gets a lot of comments from people. But often I have a problem with spammers that post images...
|
by: garethharvey |
last post by:
Hello, I am new here, but read many posts over the past year or so which has helped my business.
We have a dedicated server running a script to call a remote XML file using the following code:
...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
| |