Results 1 to 8 of 8
  1. #1
    cpbittner is offline Novice
    Windows 8 Access 2013
    Join Date
    Aug 2013
    Posts
    11

    Updating a field after updating another field - function name not found

    I need to update one field on a subform after another field on that same subform has been updated, I have created a subroutine on the subform to do this, and am calling it from the After Update Event, but I am getting the error that the function name cannot be found. I have attached the screen showing my current structure, why is Access having issues seeing the subroutine, - which I have tried to define as public as well?



    P.S. I will also note that I have tried a direct expression such as "[NextJobDate] = [LastJobDate]" - which did not do anything, but also did not cause any errors.


    Click image for larger version. 

Name:	fieldEventSetup.jpg 
Views:	12 
Size:	100.8 KB 
ID:	15609Click image for larger version. 

Name:	subroutine.jpg 
Views:	12 
Size:	69.9 KB 
ID:	15610

  2. #2
    cpbittner is offline Novice
    Windows 8 Access 2013
    Join Date
    Aug 2013
    Posts
    11
    If I change the subroutine to a Public Function, I not able to see it under functions in the expression builder, either, so I assume I am creating the subroutine/function in the incorrect location.


    Public Function setNextDate()
    If Not IsNull(Me.LastJobDate) Then
    Me.NextJobDate = Me.LastJobDate
    End If
    End Function

  3. #3
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,902
    Saving data dependent on other data is usually a bad idea. I don't understand what you are doing. Why would these two dates be equal for the same record? But the image shows the dates are different.

    A Sub cannot be called from the property. Is this procedure being called from several locations?
    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.

  4. #4
    cpbittner is offline Novice
    Windows 8 Access 2013
    Join Date
    Aug 2013
    Posts
    11
    The code I am using is just a test snippet. Basically I need to know how to have one field (field A), update the value of another (field B), without using a calculated text field since I need to be able to override the field B value if needed. The update just needs to occur on this one subform.

  5. #5
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,902
    In the control AfterUpdate event property select [Event Procedure], click the ellipsis (...) to open the VBA editor, type code.

    Me.NextJobDate = Me.LastJobDate
    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.

  6. #6
    cpbittner is offline Novice
    Windows 8 Access 2013
    Join Date
    Aug 2013
    Posts
    11
    That resolved my issue, I was not getting the right syntax in place, thank you.

  7. #7
    cpbittner is offline Novice
    Windows 8 Access 2013
    Join Date
    Aug 2013
    Posts
    11
    My original issue is fixed, but since it is related adding it to this post. I am getting a Type Mismatch error after the NextJobDate date is correctly updated and I click on another field. All fields are set to short date, the error indicates that "The expression may not result in the name if a macro, ...or [Event Procedure] - and as this is an event procedure I guess that is the issue, but yet it does update the field correctly. Code example is below.

    Before I get asked why I am storing the NextJobDate versus just making it a generated field on the query the reason is that the NextJobDate is only partially based on when the job was last done, so even though the ideal date is based on the lastJobDate + the number of days between jobs, there is on occasion the need to manually adjust the nextJobDate whcih is used for scheduling, and that date needs to be stored in its modified state.



    Private Sub LastJobDate_AfterUpdate()
    If Me.Frequency > 1 Then
    Dim tmpNextJobDate As Date
    tmpNextJobDate = DateAdd("d", Me.Frequency, Me.LastJobDate)
    Me.NextJobDate = tmpNextJobDate
    End If
    End Sub

  8. #8
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,902
    I don't know why that error triggers. The code looks fine.
    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.

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

Similar Threads

  1. Updating one date field based on another
    By barryg80 in forum Forms
    Replies: 4
    Last Post: 04-19-2013, 03:17 AM
  2. Updating Field in Table
    By tn_developer in forum Access
    Replies: 3
    Last Post: 09-29-2012, 04:12 PM
  3. Updating field goes to wrong record
    By chrismalan in forum Forms
    Replies: 7
    Last Post: 03-20-2011, 08:07 PM
  4. Help Updating Form Field
    By emarchant in forum Access
    Replies: 3
    Last Post: 10-08-2010, 11:07 AM
  5. Updating a field
    By JohnBoy in forum Programming
    Replies: 24
    Last Post: 04-18-2010, 08:43 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