?
Solved

MS Access Form - Checkbox selected not updating True/False

Posted on 2016-09-26
6
Medium Priority
?
53 Views
Last Modified: 2016-09-27
Hi,

Don't know very much about forms so sorry if this is a roundabout way of describing my isssue.

I have a table of sales orders that includes a Yes/No field added on called 'SelectedPrint'. I've added this field onto a continuous form as a checkbox so and when the user checks an order, they can print it by clicking a button which runs a vba coded event to run a report for all orders in he order table where 'SelectedPrint' is true.

    strSQL = "SELECT Contracts.InvoiceNum FROM Contracts WHERE (((Contracts.SelectedPrint)=True));"

Open in new window


This works for the most part, however the very last order I tick as Print Selected never prints.

I've found that if I click the checkbox, then click the background of the form so the checkbox is selected but not active (i.e the little pencil and dashed border around the object disappears) then it will actually print the order.

Is there anything I need to change in my code or object properties to get around this?

Many thanks,
0
Comment
Question by:Jack Marley
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
6 Comments
 
LVL 23

Expert Comment

by:Ferruccio Accalai
ID: 41816285
When you click the checkbox you go to the next record so the prev record get a post, but when you click on the last and then click the button to print that record won't be posted. Add a table.post in your code before the query.
0
 

Author Comment

by:Jack Marley
ID: 41816334
Woops I'd actually posted an old code.

Would the same apply to this one?:

Private Sub Command2_Click()
Forms!Form1.SetFocus
Dim rst As DAO.Recordset

Set rst = CurrentDb.OpenRecordset("SELECT DISTINCT [Account], [InvoiceNum] FROM [ContactTotals] WHERE (((Contracts.SelectedPrint)=True)) ORDER BY [Account];", dbOpenSnapshot)
Set rst2 = CurrentDb.OpenRecordset("SELECT DISTINCT [InvoiceNum] FROM [ContactTotals] ORDER BY [InvoiceNum];", dbOpenSnapshot)

Do While Not rst.EOF
    strRptFilter = "[InvoiceNum] = " & Chr(34) & rst![InvoiceNum] & Chr(34)

    DoCmd.OutputTo acOutputReport, "InvTotal", acFormatPDF, "C:\Scripts" & "\" & rst![Account] & " - " & rst![InvoiceNum] & ".pdf"
    DoEvents
    rst.MoveNext
   
Loop

rst.Close
Set rst = Nothing

End Sub

Open in new window

0
 
LVL 2

Expert Comment

by:Saadia Attias
ID: 41816398
Hi
1)You didn't declare rst2
2)Why  did you define rst2, it seems that you don't use it at all
3)Can you precise what do you want to do exactly
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 23

Accepted Solution

by:
Ferruccio Accalai earned 2000 total points
ID: 41816430
Yes, that rst2 is not needed (I remember that we have already disscussed about this piece of code).

Anyway try adding a savecord in the Command2_Click()

I mean:
Private Sub Command2_Click()
DoCmd.RunCommand acCmdSaveRecord
Forms!Form1.SetFocus
Dim rst As DAO.Recordset

Set rst = CurrentDb.OpenRecordset("SELECT DISTINCT [Account], [InvoiceNum] FROM [ContactTotals] WHERE (((Contracts.SelectedPrint)=True)) ORDER BY [Account];", dbOpenSnapshot)

Do While Not rst.EOF
    strRptFilter = "[InvoiceNum] = " & Chr(34) & rst![InvoiceNum] & Chr(34)

    DoCmd.OutputTo acOutputReport, "InvTotal", acFormatPDF, "C:\Scripts" & "\" & rst![Account] & " - " & rst![InvoiceNum] & ".pdf"
    DoEvents
    rst.MoveNext
   
Loop

rst.Close
Set rst = Nothing

End Sub

Open in new window

0
 
LVL 51

Expert Comment

by:Gustav Brock
ID: 41816481
You can also set Dirty off:
Private Sub Command2_Click()

    Dim rst As DAO.Recordset

    If Me.Dirty = True Then
        ' Record is not saved.
        Me.Dirty = False
    End If


    Set rst = CurrentDb.OpenRecordset("SELECT DISTINCT [Account], [InvoiceNum] FROM [ContactTotals] WHERE (((Contracts.SelectedPrint)=True)) ORDER BY [Account];", dbOpenSnapshot)

    Do While Not rst.EOF
        strRptFilter = "[InvoiceNum] = " & Chr(34) & rst![InvoiceNum] & Chr(34)

       DoCmd.OutputTo acOutputReport, "InvTotal", acFormatPDF, "C:\Scripts" & "\" & rst![Account] & " - " & rst![InvoiceNum] & ".pdf"
       DoEvents
       rst.MoveNext
   
    Loop

    rst.Close
    Set rst = Nothing

End Sub

Open in new window

/gustav
0
 

Author Closing Comment

by:Jack Marley
ID: 41817858
Thanks again Ferrucio! Yes you're right that's a remnant of my previous code before you cleaned/fixed it for me.
0

Featured Post

What Is Blockchain Technology?

Blockchain is a technology that underpins the success of Bitcoin and other digital currencies, but it has uses far beyond finance. Learn how blockchain works and why it is proving disruptive to other areas of IT.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Access developers frequently have requirements to interact with Excel (import from or output to) in their applications.  You might be able to accomplish this with the TransferSpreadsheet and OutputTo methods, but in this series of articles I will di…
In Part II of this series, I will discuss how to identify all open instances of Excel and enumerate the workbooks, spreadsheets, and named ranges within each of those instances.
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
Suggested Courses

801 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question