Results 1 to 9 of 9
  1. #1
    HotsauceHero is offline Novice
    Windows 7 32bit Access 2007
    Join Date
    Oct 2014
    Location
    Florida
    Posts
    5

    User Defined Function Returns Ambiguous Name Error

    First, please be a bit patient with me as I am picking Access/VBA back up after not doing it for seven or so years. It's amazing what you can pickup immediately and what has to be drawn from the depths.



    That being said here is my issue:

    I am trying to change field names in a table, but I don't know if my code is right because I can't get it to run!

    Here is the code:



    Private Sub Command8_Click()
    DoCmd.OpenQuery "qryUsageTotals2", acViewNormal, acReadOnly
    DoCmd.DeleteObject acTable, "tblInventory"
    DoCmd.Rename "tblInventory", acTable, "tblInventoryTest"
    Public Function chgfldnm()


    End Function
    End Sub




    Public Function chgfldnm(Qty As String, QtyTest As String)

    Dim db As Database
    Dim tbf As TableDef
    Dim n As Object

    Set db = CurrentDb
    Set tbf = TableDefs("tblInventory")
    For Each n In tdf.Fields
    If n.Name = QtyTest Then n.Name = Qty
    Next n

    Set tdf = Nothing
    Set db = Nothing
    End Function

    End Function


    When I try to run or compile I get:

    Compile Error:
    Ambiguous name detected:chgfldnm

    I have searched the net for four hours trying to find an answer. Please Help!!!!!

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,930
    That usually means duplicate procedure name, either another procedure or a module have same name.
    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.

  3. #3
    HotsauceHero is offline Novice
    Windows 7 32bit Access 2007
    Join Date
    Oct 2014
    Location
    Florida
    Posts
    5
    Nope, that's all the code.

  4. #4
    HotsauceHero is offline Novice
    Windows 7 32bit Access 2007
    Join Date
    Oct 2014
    Location
    Florida
    Posts
    5
    this is the line the compiler stops at:

    Public Function chgfldnm(Qty As String, QtyTest As String)

  5. #5
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,930
    Look at the Sub procedure. The function declaration is duplicated within the Sub. Cannot have a procedure within another procedure. And that's where the duplication is.
    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
    HotsauceHero is offline Novice
    Windows 7 32bit Access 2007
    Join Date
    Oct 2014
    Location
    Florida
    Posts
    5
    So the function is defined properly, I was trying to CALL the function in the sub. God I've forgotten so much.

  7. #7
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,930
    A function is used to return a value to the calling procedure.
    To call a function, must be used in an expression, like:

    x = chgfldnm(data1, data2)

    Perhaps it should just be declared as a sub, then call the sub:

    Call chgfldnm(data1, data2)

    Just noticed the End Function line is duplicated at the end of the function.

    Why are you programmatically changing field name?
    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.

  8. #8
    HotsauceHero is offline Novice
    Windows 7 32bit Access 2007
    Join Date
    Oct 2014
    Location
    Florida
    Posts
    5
    I was trying to update inventory totals in tblInventory by minusing sold inventory from existing inventory. I bombed on an update query, so I was trying to create a new table and rename it and the fields to the old table name. Dirty, I know.

  9. #9
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,930
    Why write code just to create a table?

    The bigger question is: Why are you saving aggregate data? Aggregate data should be calculated when needed. Sum product in, sum product out, calculate the difference. Review: http://allenbrowne.com/AppInventory.html
    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. How to use User Defined Function in VBA
    By sbehera in forum Programming
    Replies: 7
    Last Post: 05-12-2014, 07:38 AM
  2. Replies: 3
    Last Post: 11-12-2013, 04:13 PM
  3. Replies: 1
    Last Post: 12-14-2012, 12:32 AM
  4. Replies: 4
    Last Post: 06-08-2012, 09:08 AM
  5. Query using a User defined function for dates
    By RonanM in forum Programming
    Replies: 4
    Last Post: 06-16-2011, 04:04 AM

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