Results 1 to 5 of 5
  1. #1
    JDenham is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Nov 2014
    Posts
    15

    Question Updating a table field in a form using Public Function

    I have created a Public Function that would get a new Production Instructions number based off the [PI Number] of Tbl_Production_Instruction table.
    I have a form that people will put in all information but the PI Number, then when ready they will click a button to update the PI Number. I place
    an unbound txtbox that will be hidden, with the control source to =NewPINum(), but when I tested the see if the unbound txtbox was populated with
    the new PI Number it was blank. I have done this before but can't figure out what I am doing wrong. Any suggestions
    Code:
    Public Function NewPINum() As String
    Dim vNum As String


    Dim strYYMM As String
    Dim getnextPI As String
    strYYMM = Format(Date, "yy") & "-" & Format(Date, "mm") & "-"
    If strYYMM = Left(DMax("[PI Number]", "Tbl_Production_Instruction"), 6) Then
    vNum = Right(DMax("[PI Number]", "Tbl_Production_Instruction"), 3)
    vNum = vNum + 1
    getnextPI = Format(Date, "yy") & "-" & Format(Date, "mm") & "-" & Format(vNum, "000")
    Else
    vNum = "001"
    getnextPI = Format(Date, "yy") & "-" & Format(Date, "mm") & "-" & Format(vNum, "000")


    End If
    End Function

    Thanks,

  2. #2
    orange's Avatar
    orange is offline Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,848
    Did you Requery the textbox or the Form?

  3. #3
    JDenham is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Nov 2014
    Posts
    15
    Yes, I have tried to Requery on both the form and the textbox, I have stepped through the code and the "getnextPI" gives me the correct value.

  4. #4
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,625
    You need to set the function to return value to calling source.

    End If
    NewPINum = getnextPI

    Or just replace both getnextPI references with NewPINum and don't need the getnextPI variable.
    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.

  5. #5
    JDenham is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Nov 2014
    Posts
    15
    Thanks, June7 that did the trick.

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

Similar Threads

  1. Public variable not updating for each function
    By Ruegen in forum Programming
    Replies: 3
    Last Post: 08-28-2014, 06:26 PM
  2. NOW() Function not updating into table
    By joycesolomon in forum Programming
    Replies: 7
    Last Post: 08-13-2014, 06:17 PM
  3. Replies: 7
    Last Post: 03-02-2014, 08:47 PM
  4. Making a Public Function more flexible
    By sjs94704 in forum Programming
    Replies: 2
    Last Post: 12-10-2012, 02:21 PM
  5. Updating Table field from Form
    By Kunuk in forum Access
    Replies: 0
    Last Post: 02-26-2009, 11:41 PM

Tags for this Thread

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