Page 2 of 3 FirstFirst 123 LastLast
Results 16 to 30 of 42
  1. #16
    Kev86 is offline Advanced Beginner
    Windows 10 Office 365
    Join Date
    Dec 2022
    Posts
    36
    Yes we have a backend stored on the companies server and then everyone has a frontend stored locally on their PC's. I will have a read of that article you sent me to see whether it can help with what i need it to do at all. Thank you.

  2. #17
    Kev86 is offline Advanced Beginner
    Windows 10 Office 365
    Join Date
    Dec 2022
    Posts
    36
    Minty yes good point that the table based macro then works regardless of where the update is being made, i will need to add code to all the relevant forms if i move it over to a form based control rather than table based.

    You mention i have nothing to lose by moving the process to the appropriate forms but do you know how i can do this? I can't find a way to produce the same end result using VBA in a form as i have done with using the macro in the table, any ideas on how to do this?

  3. #18
    orange's Avatar
    orange is offline Moderator
    Windows 10 Office 365
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,725

  4. #19
    Minty is offline VIP
    Windows 10 Office 365
    Join Date
    Sep 2017
    Location
    UK - Wiltshire
    Posts
    3,003
    The basic premise would be to use a function/module to do the insert and call it wherever you need it.
    I do a similar thing for logging who runs reports which can't be detected by a data change, this simply records who (a global empid set at user login), when (Now()) and the report name, but your's would be two simple processes, something like (AirCode Untested)

    Code:
    Public Sub subUpdateQuoteSent(strSAP as String)
        
           
        strSQL = "INSERT INTO TATQuotesSent  (SAP , ChangedDate) VALUES ('" & strSAP & "' , NOW() )"
        'Debug.Print strSQL
        CurrentDb.Execute strSQL , dbfailonerror + dbseechanges
    
    End SUB
    I've assumed that SAP is a String in the above.
    You would simply pass the SAP value into the sub from wherever it is updated.

    Create a similar sub for your other insert/updates in the JobCat
    DLookup Syntax and others http://access.mvps.org/access/general/gen0018.htm
    Please use the star below the post to say thanks if we have helped !
    ↓↓ It's down here ↓↓

  5. #20
    Kev86 is offline Advanced Beginner
    Windows 10 Office 365
    Join Date
    Dec 2022
    Posts
    36
    Thank you Orange, i will take a look at that.

  6. #21
    Kev86 is offline Advanced Beginner
    Windows 10 Office 365
    Join Date
    Dec 2022
    Posts
    36
    Minty sorry but i am a real amateur when it comes to code and like i said in my original post all my build is based on reading online. I believe i have built the module now and i have named it UpdateQuoteSent with the code you provided above. However how do i call upon that module to run within my VBA code for the forms AfterUpdate event?

    Also if it helps SAP is our main reference number so i want whatever the SAP number is in my Jobs table to be entered into the TATQuotesSent table

    Thank you for helping with me this.

  7. #22
    Minty is offline VIP
    Windows 10 Office 365
    Join Date
    Sep 2017
    Location
    UK - Wiltshire
    Posts
    3,003
    Assuming you can identify the correct event to put this against in your form you would simply use

    Code:
    UpdateQuoteSent  Me.YourSapNumberControl
    That's it! Obviously replace YourSapNumberControl with the name of the control on your form(s)
    DLookup Syntax and others http://access.mvps.org/access/general/gen0018.htm
    Please use the star below the post to say thanks if we have helped !
    ↓↓ It's down here ↓↓

  8. #23
    Kev86 is offline Advanced Beginner
    Windows 10 Office 365
    Join Date
    Dec 2022
    Posts
    36
    Hi Minty, thank you for your help with this. I am not too used to all the code so i am struggling a bit to be honest. I have created the module and named it 'UpdateQuoteSent' with the code you kindly provided. See below..

    Click image for larger version. 

Name:	AccessForum4.png 
Views:	13 
Size:	10.1 KB 
ID:	49303

    I have then opened the form i want the update to occur on and within the QuoteSent field of that form i have selected an AfterUpdate event and added the following VBA code...

    Click image for larger version. 

Name:	AccessForum5.png 
Views:	13 
Size:	4.5 KB 
ID:	49304

    However when i then open the form in View and update the QuoteSent field i am met with an error which says 'Compile Error: expected variable or procedure, not module'.

    I am obviously doing something very wrong as i am not even sure if the name of the control on the form is correct as it gave me lots of options and i selected the AfterUpdate control but not sure if this is correct. I even set the code to UpdateQuote Sent Me.QuoteSent and this still didn't work so not sure what I need to do to fix this.

  9. #24
    Minty is offline VIP
    Windows 10 Office 365
    Join Date
    Sep 2017
    Location
    UK - Wiltshire
    Posts
    3,003
    Your second bit isn't correct.
    You need to pass the sub the value of your SAP number, so you need the name of the control that holds the SAP number on the form.


    UpdateQuoteSent Me.Put the name of the control that holds the SAP number in here


    Also ensure that you have saved the Code into a module that ISN'T called UpdateQuoteSent .
    The module name cannot be same as the function.
    Call It modAuditing or something similar.
    DLookup Syntax and others http://access.mvps.org/access/general/gen0018.htm
    Please use the star below the post to say thanks if we have helped !
    ↓↓ It's down here ↓↓

  10. #25
    Kev86 is offline Advanced Beginner
    Windows 10 Office 365
    Join Date
    Dec 2022
    Posts
    36
    Minty, thank you. I have amended the name of the module to modQuoteSentLog as i had originally named it UpdateQuoteSent. I then amended the AfterUpdate code to UpdateQuoteSent Me.SAP as the SAP field is the name of the field that holds the SAP reference number.

    However i have just tried this again and still get the same error saying that the Sub or Function not defined. Sorry to be such a pain.

  11. #26
    Minty is offline VIP
    Windows 10 Office 365
    Join Date
    Sep 2017
    Location
    UK - Wiltshire
    Posts
    3,003
    In the module code you posted up I think its called subUpdateQuoteSent not just UpdateQuoteSent

    Change one or the other so they match, sorry I didn't spot that earlier.
    DLookup Syntax and others http://access.mvps.org/access/general/gen0018.htm
    Please use the star below the post to say thanks if we have helped !
    ↓↓ It's down here ↓↓

  12. #27
    Kev86 is offline Advanced Beginner
    Windows 10 Office 365
    Join Date
    Dec 2022
    Posts
    36
    minty it works, thank you so much for helping. I want to look into it in more detail as i Have 17 macros currently built into the main table which i need to look into and replicate into the forms so i might need some extra help with them but hopefully most of them are straight forward ones i can work out myself. I have already tested this for a Cancelled update and created a new module called modCancelled and created an AfterUpdate reference to log the change and that worked also.

    How easy is it to make the module add the user name to a new field within one of my tables. So for example i currently have a table called LDEAllocatingLog which has 4 fields, these are SAP, Job Cat, Change Date & User. I think i am ok with SAP, Job Cat and Change Date but how do i get it to include the user name of who made the change?

    if it helps here is a screenshot of the current macro linked to the table...

    Click image for larger version. 

Name:	AccessForum6.png 
Views:	13 
Size:	13.5 KB 
ID:	49306

    Thanks again for all you time and help you have given me so far.

  13. #28
    Minty is offline VIP
    Windows 10 Office 365
    Join Date
    Sep 2017
    Location
    UK - Wiltshire
    Posts
    3,003
    You already have a function that is producing that called fOSUsername pretty certain you can use that in your insert query directly.
    The easy way to create the function is to initially create a query in the designer that will insert a fixed record, and then adjust to take passed in values.
    Then switch to SQL view to give you the correct syntax.

    So something like

    Code:
    INSERT Into LDEAllocatinglog (SAP, User, ChangeDate, NewValue) 
    VALUES ('132456ABC' , fOSUsername(), Now(), 'MyTestValue' )
    Would be the end result.

    You then need to create the module to take the changeable elements (in this case the SAP number and the new value) and concatenate them into the SQL string.
    Remember that any string values need to be delimited either by single quotes ' ' or triple quotes to escape any quote characters that might be present. So the above would be

    Now () , '" & strNewValue & "' )"

    or """ & & strNewValue & """ )"

    I hope that makes sense.
    DLookup Syntax and others http://access.mvps.org/access/general/gen0018.htm
    Please use the star below the post to say thanks if we have helped !
    ↓↓ It's down here ↓↓

  14. #29
    Kev86 is offline Advanced Beginner
    Windows 10 Office 365
    Join Date
    Dec 2022
    Posts
    36
    So i attempted something before you wrote back and ended up with the following code but i got an error when i tried to run it from a form. I have probably done something wrong with the single or triple quotes...

    Click image for larger version. 

Name:	AccessForum7.png 
Views:	12 
Size:	27.1 KB 
ID:	49307

  15. #30
    Minty is offline VIP
    Windows 10 Office 365
    Join Date
    Sep 2017
    Location
    UK - Wiltshire
    Posts
    3,003
    It looks okay to me.
    If you uncomment the debug.print it will show you what it is evaluating to in the immediate window.
    Press ctrl + G to see it in the vba editor.

    Also what error, and can you post up the actual generated SQL string (Not a photo!)
    DLookup Syntax and others http://access.mvps.org/access/general/gen0018.htm
    Please use the star below the post to say thanks if we have helped !
    ↓↓ It's down here ↓↓

Page 2 of 3 FirstFirst 123 LastLast
Please reply to this thread with any new information or opinions.

Similar Threads

  1. Macro to move completed order to another form.
    By Tylerluk1 in forum Access
    Replies: 1
    Last Post: 08-24-2015, 07:03 AM
  2. Replies: 1
    Last Post: 07-30-2015, 05:52 AM
  3. Replies: 4
    Last Post: 01-21-2015, 09:34 AM
  4. Replies: 8
    Last Post: 06-23-2014, 12:13 PM
  5. move a form with a macro
    By orcaa in forum Programming
    Replies: 1
    Last Post: 01-19-2013, 11:31 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