Results 1 to 6 of 6
  1. #1
    Akchayan is offline Competent Performer
    Windows 7 64bit Access 2016
    Join Date
    Aug 2022
    Posts
    102

    Transfer values from report to table


    Hello everyone,


    I have this report here:
    Click image for larger version. 

Name:	s.png 
Views:	21 
Size:	33.7 KB 
ID:	48714
    (The arrow points to a box, the variable in the box is called: "ID".)
    I would like to transfer the value (marked with a green arrow) into the table "tblOfferte"(The column in which it is to be written is called: "IDCustomers".) when closing the report, for this I have written this code:
    Code:
    Private Sub Report_Close()
    Dim db As DAO.Database
    Dim rs As DAO.Recordset
    
    
    
    
    Set db = CurrentDb
    
    
    
    
    'Save Payroll Record'
    
    
        Set rs = db.OpenRecordset("tblOfferte")
            With rs
                .AddNew
                !IDCustomer = ID
              
                .update
            End With
        rs.Close
        Set rs = Nothing
        db.Close
        Set db = Nothing
        
        
    End Sub
    but it does not work.
    How would it work?
    Thanks for the help!

  2. #2
    Micron is online now Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,801
    Is the value in some other table? If so it's very odd that you'd want to copy it to another table or field and even more odd that you'd want to get it from a report?
    To get to your point, it could be because you're using the report close event for this, but I'm not real confident of that. Reports are weird in that they seem to behave the opposite way than forms do. Reports close first, then unload. You could try putting a breakpoint at the start of the code, attempt to close the report and step thru with F8 to see if it makes a difference. If it does, it could be a timing issue.

    BTW, what does "does not work" mean?
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  3. #3
    Akchayan is offline Competent Performer
    Windows 7 64bit Access 2016
    Join Date
    Aug 2022
    Posts
    102
    Quote Originally Posted by Micron View Post
    Is the value in some other table? If so it's very odd that you'd want to copy it to another table or field and even more odd that you'd want to get it from a report?
    To get to your point, it could be because you're using the report close event for this, but I'm not real confident of that. Reports are weird in that they seem to behave the opposite way than forms do. Reports close first, then unload. You could try putting a breakpoint at the start of the code, attempt to close the report and step thru with F8 to see if it makes a difference. If it does, it could be a timing issue.

    BTW, what does "does not work" mean?
    The value has to be entered by the user in a form, then he presses a button and it creates a PDF and closes automatically.
    By it not working, I mean that this error occurs:

    "Runtime error 2427

    You have entered an expression without a value."

  4. #4
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,940
    Try the actual expression that control ID contains?

    As always, WALK ​ through your code line by line and see what you actually have, not what you think you have.
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  5. #5
    moke123's Avatar
    moke123 is offline Me.Dirty=True
    Windows 11 Office 365
    Join Date
    Oct 2012
    Location
    Ma.
    Posts
    1,654
    (The arrow points to a box, the variable in the box is called: "ID".)
    Is the textbox itself named "ID"?
    I would try using the me. keyword with ID to be sure. Intellisense should kick in.
    Code:
    !IDCustomer = Me.ID
    If this helped, please click the star * at the bottom left and add to my reputation- Thanks

  6. #6
    Micron is online now Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,801
    I think you're saying the needed value is in the report control that references the form (the one the green arrow points to), so why not use that? Maybe
    !IDCustomer = Formular!foOfferteKundenDat ...
    I can't see the rest of that so I put ellipses.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

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

Similar Threads

  1. Replies: 3
    Last Post: 04-28-2014, 07:22 AM
  2. Replies: 10
    Last Post: 11-19-2012, 11:05 AM
  3. form data transfer to a report
    By poppinggizmo in forum Forms
    Replies: 1
    Last Post: 06-06-2010, 09:00 PM
  4. Transfer data from ListView to Table
    By Zyckie in forum Access
    Replies: 1
    Last Post: 12-15-2009, 11:23 AM
  5. Replies: 3
    Last Post: 04-23-2006, 09:09 PM

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