Results 1 to 14 of 14
  1. #1
    Join Date
    Jun 2015
    Location
    Wales. Land of the sheep.
    Posts
    1,228

    Broken VBA

    Error:

    Code:
    Runtime error '3061'
    
    too few parameters. Expected 1.
    Code:


    Code:
    Private Sub Scheduled_Start_AfterUpdate()
    Dim strSql As String
     Dim strNote As String
         strNote = InputBox("Reason for change:", _
                  "Rescheduling Tracker")
     strSql = "UPDATE AuditT SET AuditT.Note = '" & strNote & "' WHERE me.jobf.Job_ID"
    CurrentDb.Execute strSql
        
    End Sub
    Debugger highlights:

    Code:
    CurrentDb.Execute strSql

    This is a continuation from a few weeks ago when I was working on this. Basically I have an audit table which tracks date changes. This code is so the user has to input why they change it..

    Some things have changed since then.

    Jobf now has a subform called workdays. Day_ID is now the record that is changing.


    with the setup shown in the code I was getting the input box and then the error.


    Now when I change

    WHERE me.jobf.Job_ID
    to
    WHERE me.workdays.day_ID

    I get no errors but I don't get an input box either.

    I want to add a bit more functionality to this code so I'm keen to resolve it if someone could help.

    Cheers.

    edit: The input box is now showing. Same error persists

  2. #2
    JamesDeckert is offline Competent Performer
    Windows 7 64bit Access 2013
    Join Date
    Jul 2015
    Location
    Salina, KS
    Posts
    262
    shouldn't "UPDATE AuditT SET AuditT.Note = '" & strNote & "' WHERE me.jobf.Job_ID"
    be
    "UPDATE AuditT SET AuditT.Note = '" & strNote & "' WHERE " & me.jobf.Job_ID
    it's always helpful to drop into debug and look at any dynamically build sql to see what it looks like. It usually clears up problems.

  3. #3
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 8 Access 2013
    Join Date
    Aug 2013
    Posts
    7,862
    You are missing the name of your field, too.

    strSql = "UPDATE AuditT SET AuditT.Note = '" & strNote & "' WHERE [MyField] = " & me.jobf.Job_ID

  4. #4
    Join Date
    Jun 2015
    Location
    Wales. Land of the sheep.
    Posts
    1,228
    Thanks for the replies.

    ItsMe I've added the field now.

    James (or anyone that wishes to answer)
    this is the updated code:
    Code:
    UPDATE AuditT SET AuditT.Note = '" & strNote & "' WHERE Day_ID = me.workdays.Day_ID
    Where do I add your & symbol..

    thanks so far,

    also
    Code:
    it's always helpful to drop into debug and look at any dynamically build sql to see what it looks like
    I'm not sure what you mean by this. When there is a problem I click debug and see which line is highlighted. Is that what you mean or is there something else I can do ?

  5. #5
    Join Date
    Jun 2015
    Location
    Wales. Land of the sheep.
    Posts
    1,228
    Update:

    It took me a few hours to figure out how I got the audit table working in the first place. I now see why this code has no chance of working.

    I have a macro on the workdays table which runs after update on "scheduled_start".

    Click image for larger version. 

Name:	NewMacro#.png 
Views:	28 
Size:	9.2 KB 
ID:	22436

    So.. we cant update depending on Day_ID because the audit table will have many changes relating to one day. I think the input needs to be made the same time as the macro runs. either by adding to the existing macro or converting it to vba and adding the function.

    any tips?

  6. #6
    Join Date
    Jun 2015
    Location
    Wales. Land of the sheep.
    Posts
    1,228
    surely I should be able to add another set field for the note. (as shown in the picture) then assign an input box to it.

  7. #7
    Join Date
    Jun 2015
    Location
    Wales. Land of the sheep.
    Posts
    1,228
    Can a moderator delete this and I'll start again. I believe the information here will only add to confusion now.

  8. #8
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 8 Access 2013
    Join Date
    Aug 2013
    Posts
    7,862
    Can you convert your Macro to VBA?

  9. #9
    CJ_London is offline VIP
    Windows 8 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,842
    two things about your code

    UPDATE AuditT SET AuditT.Note = '" & strNote & "' WHERE me.jobf.Job_ID

    1. your where clause refers to a control - but not like that - controls should not have . in the name
    2. Where what? should be equal to something = perhaps WHERE AuditT.Job_ID=me.jobID or AuditT.Job_ID=forms!myform!JobID

  10. #10
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,632
    Refer to link at bottom of my post for debugging guidelines. Setting a breakpoint in code and stepping through are very common techniques.
    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.

  11. #11
    Join Date
    Jun 2015
    Location
    Wales. Land of the sheep.
    Posts
    1,228
    This whole method is useless. It cant possibly work. Ill have to re structure the auditing process I think.

  12. #12
    ssanfu is offline Master of Nothing
    Windows XP Access 2010 32bit
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    Have you seen this article by Allen Browne:

    Creating an Audit Log
    http://www.allenbrowne.com/AppAudit.html

  13. #13
    Join Date
    Jun 2015
    Location
    Wales. Land of the sheep.
    Posts
    1,228
    I've seen it yes I didn't read too much into it though. Thanks for the link. I should know by the end of today if I need to restructure. I'm still hopefull I wont.

  14. #14
    Join Date
    Jun 2015
    Location
    Wales. Land of the sheep.
    Posts
    1,228
    solved - RunCommand acCmdSaveRecord before opening a form that displays the last record on the audit table.

    works a treat.

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

Similar Threads

  1. Broken Reference?
    By JeffGeorge in forum Access
    Replies: 4
    Last Post: 07-08-2014, 10:29 AM
  2. Broken reference
    By NOTLguy in forum Programming
    Replies: 5
    Last Post: 11-10-2012, 08:26 AM
  3. Broken Query
    By ThatSkepTicGuy in forum Queries
    Replies: 3
    Last Post: 09-25-2012, 09:43 AM
  4. Broken Query
    By lkevinc42036 in forum Access
    Replies: 9
    Last Post: 08-06-2012, 09:29 AM
  5. Broken reference
    By cassidym in forum Reports
    Replies: 15
    Last Post: 09-18-2011, 07:57 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