Results 1 to 9 of 9
  1. #1
    edson is offline Advanced Beginner
    Windows 8 Access 2007
    Join Date
    Oct 2014
    Posts
    57
    I'm struggling with a coding problem. I wondered if some of you guys could help me on that issue.
    Here it is:
    I have a Tbl1 which is updated by a Frm1 (record ID by record ID). Both of them include a SelectionBox Y/N type std value=0.


    There is also a Qry1 which is based on the Tbl1. This Qry1 generates a Rpt1 for each specific record ID. The Rpt1 also includes that SelectionBox as well as a PrintButton.
    My final goal is:
    By the time the user clicks the Rpt1 PrintButton I want the SelectionBox of that particular record ID of the Master Table to be updated (flagged) with -1 value. By doing that, the Qry1 will also flag -1, so do the Rpt1, meaning in case the user try to print the Rpt1 again, he'll get a message box advising him the Rpt1 has already been printed.
    In other words, I need to update a specific recordID of my Tbl1 from a Click event in the Rpt1 PrintButton.
    I did not manage to make it work. Do you know how to get it done, please? Thank you in advance.

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,771
    Post code that generates report for each specific record ID.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    edson is offline Advanced Beginner
    Windows 8 Access 2007
    Join Date
    Oct 2014
    Posts
    57
    The Qry1(QryLdAFG) SQL instructions to generate Rpt1(RepLdAFG) are:
    SELECT TblCadastro.CADID, TblCadastro.LDAFG, TblCadastro.NOMECAND, TblCadastro.SEXOCULTA, TblCadastro.ESTCIVILOCULTA, TblCadastro.ESCOCULTA, TblCadastro.IDADE, TblCadastro.CPF, TblCadastro.PROFOCULTA, TblCadastro.DTAVAL, TblCadastro.VALDT, TblCadastro.DTLDAFG, TblCadastro.ENDLOGR, TblCadastro.ENDNUM, TblCadastro.ENDCOMPL, TblCadastro.ENDBAIRRO, TblCadastro.ENDCIDSPOCULTA, TblCadastro.ENDCIDOCULTA, TblCadastro.ENDESTOCULTA, TblCadastro.ENDCEP, TblCadastro.SIAPRO, TblCadastro.CR, TblCadastro.EMPRESAADM, TblCadastro.TPFOCULTA, TblCadastro.NATOCULTA, TblCadastro.TIPOCULTA, TblCadastro.MOTOCULTA, TblCadastro.INSTREQOCULTA, TblCadastro.NINSTOCULTA, (Format([DTLDAFG],"yy")) AS ANODTLD, Format([cpf],"@@@\.@@@\.@@@-@@") AS FORMATACPF, Format([CR],"@@@\.@@@") AS FORMATACR, Format([SIAPRO],"@@@@@\.@@@@@@\/@@@@-@@") AS FORMATASIAPRO, TblCadastro.CTRIMP
    FROM TblCadastro
    GROUP BY TblCadastro.CADID, TblCadastro.LDAFG, TblCadastro.NOMECAND, TblCadastro.SEXOCULTA, TblCadastro.ESTCIVILOCULTA, TblCadastro.ESCOCULTA, TblCadastro.IDADE, TblCadastro.CPF, TblCadastro.PROFOCULTA, TblCadastro.DTAVAL, TblCadastro.VALDT, TblCadastro.DTLDAFG, TblCadastro.ENDLOGR, TblCadastro.ENDNUM, TblCadastro.ENDCOMPL, TblCadastro.ENDBAIRRO, TblCadastro.ENDCIDSPOCULTA, TblCadastro.ENDCIDOCULTA, TblCadastro.ENDESTOCULTA, TblCadastro.ENDCEP, TblCadastro.SIAPRO, TblCadastro.CR, TblCadastro.EMPRESAADM, TblCadastro.TPFOCULTA, TblCadastro.NATOCULTA, TblCadastro.TIPOCULTA, TblCadastro.MOTOCULTA, TblCadastro.INSTREQOCULTA, TblCadastro.NINSTOCULTA, Format([CR],"@@@\.@@@"), Format([SIAPRO],"@@@@@\.@@@@@@\/@@@@-@@"), TblCadastro.CTRIMP;

    CTRIMP is the Y/N SelectionBox.

    Is that what you need?

  4. #4
    edson is offline Advanced Beginner
    Windows 8 Access 2007
    Join Date
    Oct 2014
    Posts
    57
    Just FYI the code I used in the Click event of the PrintButton was:
    CurrentDb.execute "UPDATE TblCadastro SET [CTRIMP] = -1"
    However this code assigns -1 for every single record of the field CTRIMP in TblCadastro. This is not what I need.
    I need CTRIMP to be -1 on the record CADID (primary key) related to the record shown in the RepLdAFG only.
    Thanks

  5. #5
    edson is offline Advanced Beginner
    Windows 8 Access 2007
    Join Date
    Oct 2014
    Posts
    57
    So my dear June7, I'm looking for a code to be placed in the click event of the print button of the report. Does it make sense?

  6. #6
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,771
    That is a query - I assume it is the report RecordSource. I meant the code that opens the report. The code in the button click event. Are you using macro or VBA?

    If you want to provide db for analysis, follow instructions at bottom of my post.

    EDIT: Didn't see your additional posts.

    Use WHERE clause

    CurrentDb.execute "UPDATE TblCadastro SET [CTRIMP] = -1 WHERE CADID=" & Me.CADID
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  7. #7
    edson is offline Advanced Beginner
    Windows 8 Access 2007
    Join Date
    Oct 2014
    Posts
    57
    Jun 7, still in time:
    In addition, there is a button in the Frm1(FrmCadastro) which has the following code on its click event:
    DoCmd.OpenReport "RepLaudoAFG", acViewReport, , "CADID = " & CADID

    I believe this is useful info for you.
    Thanks for your attention.

  8. #8
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,771
    Posts are crossing. Was editing my previous post, might look at again.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  9. #9
    edson is offline Advanced Beginner
    Windows 8 Access 2007
    Join Date
    Oct 2014
    Posts
    57
    Yyyaaheeeeeeeeeeeeeeeee!!!! Wonderful!!! It worked as a charm!!! Thank you, thank you, thank you.
    I felt myself embarassed. It took you seconds to solve a problem that took me all day long. My mistake was the sintax. I tried to use where clause but without " & characthers, that is why it did no work.
    Thank you again.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Code to Update Checkbox on Table
    By UTLee in forum Programming
    Replies: 16
    Last Post: 10-10-2014, 02:23 PM
  2. Update to a table with code
    By jlk in forum Programming
    Replies: 4
    Last Post: 01-07-2013, 03:37 AM
  3. Reusing VBA Code To Update A Table
    By Evilferret in forum Programming
    Replies: 3
    Last Post: 08-28-2012, 07:30 AM
  4. VBA code to update field in table
    By vickan240sx in forum Access
    Replies: 1
    Last Post: 06-23-2012, 08:24 PM
  5. Replies: 3
    Last Post: 04-14-2010, 10:07 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums