I have a master DB that opens a secondary database using a timer to run invoices. When the secondary database opens, the invoice form loads and the cmd button to run the invoices is set to focus. The following code should run, however it is not. The only changes to the code is the now instead of linking to Access tables [tblInvoice AutoTemp] it now links to sql tables [dbo_tblInvoice AutoTemp]. This was originally written in Access 2003 and is now being used in Access 2010. Since I didn't write the code I'm not sure where to look to see if what the issue is. I've already verified that none of the invoices has been checked as having been generated.
Thanks!
Leesha
Code: Select all
Dim strWhere As String
Dim strSQL As String
Dim dbs As DAO.Database
Dim rst As DAO.Recordset
Dim strFilename As String
'Prints Non-Beverage Cup Invoices
' Create the where-condition
strWhere = " WHERE InvoiceGenerated = False AND BeverageStore = False"
If Not IsNull(Me.txtStart) Then
strWhere = strWhere & " AND BillingPeriodStartDate >= #" & Format(Me.txtStart, "yyyy-mm-dd") & "#"
End If
If Not IsNull(Me.txtEnd) Then
strWhere = strWhere & " AND BillingPeriodEndDate <= #" & Format(Me.txtEnd, "yyyy-mm-dd") & "#"
End If
' strSQL = "SELECT * FROM [dbo_tblInvoice AutoTemp]" & strWhere
' ***** Change 500 to the number of records to process *****
strSQL = "SELECT TOP 400 * FROM [dbo_tblInvoice AutoTemp]" & strWhere
Set dbs = CurrentDb
Set rst = dbs.OpenRecordset(strSQL, dbOpenDynaset, dbSeeChanges)
Do While Not rst.EOF
glngInvoiceID = rst!InvoiceID
strFilename = gstrPath & rst!WalmartNumber & "-" & _
rst!Store_ID & Format(Me.txtStart, " m.yy") & ".pdf"
ConvertReportToPDF "rptInvoiceAuto", , strFilename, , False
' Set InvoiceGenerated field to True
rst.Edit
rst!InvoiceGenerated = True
rst.Update
rst.MoveNext
Loop
'Prints beverage cup invoice
'Prints Non-Beverage Cup Invoices
' Create the where-condition
strWhere = " WHERE InvoiceGenerated = False AND BeverageStore = True"
If Not IsNull(Me.txtStart) Then
strWhere = strWhere & " AND BillingPeriodStartDate >= #" & Format(Me.txtStart, "yyyy-mm-dd") & "#"
End If
If Not IsNull(Me.txtEnd) Then
strWhere = strWhere & " AND BillingPeriodEndDate <= #" & Format(Me.txtEnd, "yyyy-mm-dd") & "#"
End If
' strSQL = "SELECT * FROM [dbo_tblInvoice AutoTemp]" & strWhere
' ***** Change 500 to the number of records to process *****
strSQL = "SELECT TOP 400 * FROM [dbo_tblInvoice AutoTemp]" & strWhere
Set dbs = CurrentDb
Set rst = dbs.OpenRecordset(strSQL, dbOpenDynaset, dbSeeChanges)
Do While Not rst.EOF
glngInvoiceID = rst!InvoiceID
strFilename = gstrPath & rst!WalmartNumber & "-" & _
rst!Store_ID & Format(Me.txtStart, " m.yy") & ".pdf"
ConvertReportToPDF "rptInvoiceAutoBevAuto", , strFilename, , False
' Set InvoiceGenerated field to True
rst.Edit
rst!InvoiceGenerated = True
rst.Update
rst.MoveNext
Loop
'Closes Database
' DoCmd.Quit
rst.Close
Set rst = Nothing
Set dbs = Nothing