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.
[imgnothumb]http://bytes.com/attachments/attachment/7071d1373209113/screen.jpg[/imgnothumb]
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.
Code:
Option Compare Database Option Explicit
Code:
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
Code:
Private Sub cbx1_AfterUpdate() Form_frmDonations2.subform2.Requery End Sub
Code:
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
Code:
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
Code:
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
Code:
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
Code:
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
Code:
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
Code:
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
Code:
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
Comment