Results 1 to 6 of 6
  1. #1
    WAVP375 is offline Competent Performer
    Windows 10 Access 2013 32bit
    Join Date
    Jul 2015
    Location
    Dayton Ohio
    Posts
    171

    Calling a subroutine

    I'm having a problem executing the following subroutine. I would call it from a sub on click routine. I would also like to pass a variable. There will be nothing returned from the subroutine. It is in a module named "Create Relation"




    Public Sub CreateRelationship()
    DoCmd.SetWarnings False
    'Create relationship
    Dim db As DAO.Database
    Dim rel As DAO.Relation
    Dim fld As DAO.Field
    Dim RelName As String
    RelName = "AWOLRelation"

    'Initialize
    Set db = CurrentDb()

    'Check if relationship already exists
    For Each rel In db.Relations
    If rel.Name = RelName Then
    DoCmd.SetWarnings True
    Exit Sub
    End If
    Next rel

    'Create a new relationship
    'Set rel = db.CreateRelation("TblAWOLNames, TblAWOLSchedule")
    Set rel = db.CreateRelation(RelName)

    'Define the properties
    With rel
    .Table = "TblAWOLNames" 'Specify primary tabl
    .ForeignTable = "TblAWOLSchedule" 'Specify related table
    .Attributes = dbRelationUpdateCascade + dbRelationDeleteCascade 'Specify attribute for cascading updates and deletes

    'Add the field to the relation
    Set fld = .CreateField("Badge #") 'Field name in primary table
    fld.ForeignName = "Badge #" 'Field name in related table
    .Fields.Append fld 'Append the field
    End With

    'Save the new relationship to the collection
    db.Relations.Append rel

    'Clean up
    Set fld = Nothing
    Set rel = Nothing
    Set db = Nothing
    DoCmd.SetWarnings True

    Exit Sub
    End Sub

  2. #2
    orange's Avatar
    orange is offline Moderator
    Windows 10 Access 2010 32bit
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,870
    WAVP375,
    A couple of things:
    -use code tags to surround your code (highlight your vba, then click the hash/octothorpe "#" button above)
    -when you have a problem
    I'm having a problem executing the following subroutine
    gives us a description or error number or the symptoms you are experiencing.
    -best to avoid a naming convention that allows embedded spaces or special characters (I suggest BadgeNo to reduce syntax errors)

    See Allen Brownes DAO Create Relation for DAO/vba


    OR this one for an SQL approach

    Good luck with your project.

  3. #3
    WAVP375 is offline Competent Performer
    Windows 10 Access 2013 32bit
    Join Date
    Jul 2015
    Location
    Dayton Ohio
    Posts
    171
    The label 'Badge #' comes from an imported excel worksheet.
    The code I am trying to use to call the previous list code is as follows:


    Private Sub Command143_Click()

    CreateRelationship
    MsgBox "Relationship created"
    End Sub

    The error I'm getting is 'Ambiguous Name detected: CreateRelationship'

    The sub routine works , I just cant' call it.



  4. #4
    davegri's Avatar
    davegri is offline Excess Access
    Windows 10 Access 2016
    Join Date
    May 2012
    Location
    Denver
    Posts
    3,742
    Ambiguous name means that you have more than one sub or function with the same name.
    Search the entire project for "CreateRelationship"

  5. #5
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,652
    Also make sure the module itself doesn't have the same name as the sub.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  6. #6
    WAVP375 is offline Competent Performer
    Windows 10 Access 2013 32bit
    Join Date
    Jul 2015
    Location
    Dayton Ohio
    Posts
    171
    Thanks guys, I got it finally.

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

Similar Threads

  1. Subroutine VBA - Jump
    By mainerain in forum Programming
    Replies: 4
    Last Post: 10-23-2019, 02:31 PM
  2. How to timeout a subroutine while it's running
    By mcucino in forum Programming
    Replies: 7
    Last Post: 04-27-2019, 05:10 PM
  3. Passing a string from one subroutine to another
    By catluvr in forum Programming
    Replies: 4
    Last Post: 08-01-2018, 03:16 PM
  4. Calling Access VBA subroutine from an Excel VBA subroutine
    By richard_yolland in forum Programming
    Replies: 0
    Last Post: 02-16-2011, 11:30 AM
  5. Referencing a Subroutine
    By Lockrin in forum Programming
    Replies: 1
    Last Post: 02-26-2010, 10:09 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