473,396 Members | 2,068 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

help with script

emandel
65
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.

Expand|Select|Wrap|Line Numbers
  1. Option Compare Database
  2. Option Explicit

Expand|Select|Wrap|Line Numbers
  1. Private Sub btn1_Click()
  2.  
  3. Dim sql1 As String
  4. Dim sql2 As String
  5. Dim sql3 As String
  6.  
  7.  
  8. Dim rst1 As DAO.Recordset
  9. Dim rst2 As DAO.Recordset
  10. Dim rst3 As DAO.Recordset
  11. Dim varnewid  As Integer
  12.  
  13.  
  14.  
  15.  
  16.  
  17. sql1 = "SELECT * FROM Donations LEFT JOIN Receipts ON Donations.Receipt = Receipts.ID WHERE Donations.Donor = " & Nz(Form_frmDonations2.cbx1) & " AND Receipts.ID Is Null"
  18. sql2 = "SELECT * from RECEIPTS"
  19. sql3 = "Select * from DONATIONS WHERE Donations.Donor = " & Nz(Form_frmDonations2.cbx1) & " and (Donations.Receipt = 0 or Donations.Receipt is null) "
  20.  
  21.  
  22.  
  23. Set rst1 = CurrentDb.OpenRecordset(sql1)
  24. Set rst2 = CurrentDb.OpenRecordset(sql2)
  25. Set rst3 = CurrentDb.OpenRecordset(sql3)
  26.  
  27.  
  28.     If (rst1.RecordCount > 0) Then
  29.         rst1.MoveLast
  30.         MsgBox (rst1.RecordCount & " Donations will be assigned a new receipt")
  31.  
  32.         With rst2
  33.             .AddNew
  34.             .Fields("timestamp") = Now()
  35.             .Update
  36.             .MoveLast
  37.  
  38.             varnewid = .Fields("ID")
  39.  
  40.         End With
  41.  
  42.  
  43.         With rst3
  44.             Do While Not .EOF
  45.             .Edit
  46.             .Fields("Receipt") = varnewid
  47.             .Update
  48.             .MoveNext
  49.             Loop
  50.         End With
  51.  
  52.     Else
  53.  
  54.         MsgBox ("There are no donations available")
  55.     End If
  56.  
  57.  
  58.  
  59. rst1.Close
  60. rst2.Close
  61. rst3.Close
  62.  
  63. Form_frmDonations2.subform2.Requery
  64.  
  65.  
  66. End Sub
Expand|Select|Wrap|Line Numbers
  1. Private Sub cbx1_AfterUpdate()
  2. Form_frmDonations2.subform2.Requery
  3.  
  4. End Sub
Expand|Select|Wrap|Line Numbers
  1. Private Sub btnprintpreview2_Click()
  2. On Error GoTo Err_btnprintpreview2_Click
  3.  
  4.     Dim stDocName As String
  5.  
  6.     stDocName = "rptDonations"
  7.     DoCmd.OpenReport stDocName, acPreview
  8.  
  9. Exit_btnprintpreview2_Click:
  10.     Exit Sub
  11.  
  12. Err_btnprintpreview2_Click:
  13.     MsgBox Err.Description
  14.     Resume Exit_btnprintpreview2_Click
  15.  
  16. End Sub
Expand|Select|Wrap|Line Numbers
  1. Private Sub btnexportword2_Click()
  2. On Error GoTo Err_btnexportword2_Click
  3.  
  4.     Dim stDocName As String
  5.  
  6.     stDocName = "mcrExportWord"
  7.     DoCmd.RunMacro stDocName
  8.  
  9. Exit_btnexportword2_Click:
  10.     Exit Sub
  11.  
  12. Err_btnexportword2_Click:
  13.     MsgBox Err.Description
  14.     Resume Exit_btnexportword2_Click
  15.  
  16. End Sub
Expand|Select|Wrap|Line Numbers
  1. Private Sub btnprintreceipt_Click()
  2. On Error GoTo Err_btnprintreceipt_Click
  3.  
  4.     Dim stDocName As String
  5.  
  6.     stDocName = "rptDonations2"
  7.     DoCmd.OpenReport stDocName, acPreview
  8.  
  9. Exit_btnprintreceipt_Click:
  10.     Exit Sub
  11.  
  12. Err_btnprintreceipt_Click:
  13.     MsgBox Err.Description
  14.     Resume Exit_btnprintreceipt_Click
  15.  
  16. End Sub
Expand|Select|Wrap|Line Numbers
  1. Private Sub btnexportword_Click()
  2. On Error GoTo Err_btnexportword_Click
  3.  
  4.     Dim stDocName As String
  5.  
  6.     stDocName = "mcrExportWord"
  7.     DoCmd.RunMacro stDocName
  8.  
  9. Exit_btnexportword_Click:
  10.     Exit Sub
  11.  
  12. Err_btnexportword_Click:
  13.     MsgBox Err.Description
  14.     Resume Exit_btnexportword_Click
  15.  
  16. End Sub
Expand|Select|Wrap|Line Numbers
  1. Private Sub btnopendoners_Click()
  2. On Error GoTo Err_btnopendoners_Click
  3.  
  4.     Dim stDocName As String
  5.     Dim stLinkCriteria As String
  6.  
  7.     stDocName = "Doners"
  8.     DoCmd.OpenForm stDocName, , , stLinkCriteria
  9.  
  10.  
  11.     Form_Doners.Filter = "Doners.ID = " & Me.cbx1 & ""
  12.     Form_Doners.FilterOn = True
  13.  
  14.  
  15. Exit_btnopendoners_Click:
  16.     Exit Sub
  17.  
  18. Err_btnopendoners_Click:
  19.     MsgBox Err.Description
  20.     Resume Exit_btnopendoners_Click
  21.  
  22. End Sub
Expand|Select|Wrap|Line Numbers
  1. Private Sub btnexport2word_Click()
  2. On Error GoTo Err_btnexport2word_Click
  3.  
  4. Call wordreceipts
  5.  
  6. Exit_btnexport2word_Click:
  7.     Exit Sub
  8.  
  9. Err_btnexport2word_Click:
  10.     MsgBox Err.Description
  11.     Resume Exit_btnexport2word_Click
  12.  
  13. End Sub
Expand|Select|Wrap|Line Numbers
  1. Private Sub Command15_Click()
  2. On Error GoTo Err_Command15_Click
  3.  
  4.  
  5.     Screen.PreviousControl.SetFocus
  6.     DoCmd.DoMenuItem acFormBar, acEditMenu, 10, , acMenuVer70
  7.  
  8. Exit_Command15_Click:
  9.     Exit Sub
  10.  
  11. Err_Command15_Click:
  12.     MsgBox Err.Description
  13.     Resume Exit_Command15_Click
  14.  
  15. End Sub
Expand|Select|Wrap|Line Numbers
  1. Private Sub Command16_Click()
  2. On Error GoTo Err_Command16_Click
  3.  
  4.  
  5.     DoCmd.GoToRecord , , acFirst
  6.  
  7. Exit_Command16_Click:
  8.     Exit Sub
  9.  
  10. Err_Command16_Click:
  11.     MsgBox Err.Description
  12.     Resume Exit_Command16_Click
  13.  
  14. End Sub

Attached Images
File Type: jpg screen.jpg (19.0 KB, 261 views)
Jul 7 '13 #1

✓ answered by zmbd

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
Expand|Select|Wrap|Line Numbers
  1. ((Donations.Receipt) 
  2.                =[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
zmbd
5,501 Expert Mod 4TB
emandel
(...)
Here is the script on the form. I know nothing about programming so please give me the instructions in plain english.
Emandel,
You must understand, you MUST have a basic understanding of VBA before we can effectively help you.

I'll leave this thread open for a little while to see if anyone is willing to wade thru all of the code, I know that I'll take a look at what appears to be the event code behind your command button... HOWEVER this WILL take quite a while to do... so... a tad of homework for you:

>> Before Posting (VBA or SQL) Code.
>> How to ask "good" questions -- READ BEFORE SUBMITTING A QUESTION!.
>> POSTING_GUIDELINES: Please Read Carefully Before Posting to a Forum.
Jul 7 '13 #2
Rabbit
12,516 Expert Mod 8TB
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.
Jul 7 '13 #3
emandel
65
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?
Jul 7 '13 #4
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...
Jul 7 '13 #5
emandel
65
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

Expand|Select|Wrap|Line Numbers
  1. SELECT Doners.ID, Doners.Title
  2.    , Doners.[First Name], Doners.[Last Name]
  3.    , Doners.Address, Doners.City
  4.    , Doners.Province, Doners.[Postal Code]
  5.    , Donations.ID, Donations.Amount
  6.    , Donations.Cheque, Donations.Date
  7.    , Donations.Year, Donations.Details
  8.    , Donations.Receipt, Receipts.timestamp
  9. FROM Receipts 
  10.    RIGHT JOIN (Doners 
  11.          RIGHT JOIN Donations 
  12.             ON Doners.ID = Donations.Donor) 
  13.       ON Receipts.ID = Donations.Receipt
  14. WHERE (
  15.         (
  16.          (Doners.ID)=[Forms]![frmDonations2]![cbx1])
  17.           AND 
  18.             ((Donations.Receipt)
  19.                =[Forms]![frmDonations2]![subform2].[Form]![Receipt]
  20.          )
  21.       );
  22.  
Jul 7 '13 #6
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
Expand|Select|Wrap|Line Numbers
  1. ((Donations.Receipt) 
  2.                =[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...
Jul 8 '13 #7
emandel
65
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
Jul 8 '13 #8
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.
Jul 8 '13 #9

Sign in to post your reply or Sign up for a free account.

Similar topics

3
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...
4
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...
6
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...
7
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...
0
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....
5
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...
2
by: Kesavan | last post by:
I need a function such that it returns a string holding the contents of function in other php file.., ...
9
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...
1
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: ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
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...
0
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
1
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...
0
marktang
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,...
0
Oralloy
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,...
0
jinu1996
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...
0
tracyyun
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...
0
agi2029
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,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.