#1
  1. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2004
    Posts
    295
    Rep Power
    46

    VBA problem - Ambiguous name detected


    Hello everyone,

    I've written a macro in word which populates a series of labels on the document and Im running into problems.

    It appears to be a problem with the label names rather than a variable name in the code though, and it changes the name of the object. For example, I have a label called lblItem1. Upon entering the document I've noticed it has been renamed to lblItem11 and attempting to change it back results in the ambiguous name detected error. I can't find any other labels on the document named lblItem1 and if I open the properties window on one of the labels and click the dropdown it isn't listed there either. However, if I enter the VBA code window I can see the name lblItem1 in my dropdown.

    This is driving me crazy as I can't work out why it's changing the names of my labels and thinking there are already labels present. Any ideas?

    If it makes a difference it is a mail merge document and once the macro is run it shuts down the original window and opens a seperate mail merge document.

    I'd really appreciate any help or guidance in the right direction.
  2. #2
  3. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2004
    Posts
    295
    Rep Power
    46
    Is anyone able to help with this? Im happy to give anymore information which may be of use.
  4. #3
  5. Humble Learner
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2007
    Location
    Bangalore, India
    Posts
    280
    Rep Power
    120
    I think you have copy and pasted the controls resulting in a control array.
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2008
    Posts
    50
    Rep Power
    29
    It may not be a case of two control having the same name but rather two objects. For example, if your procedure name has same name as the module, that would be an ambiguous name or something like that. So it's not merely a case of looking in the dropdown but also verifying that there is no other name conflict along different objects.
  8. #5
  9. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2004
    Posts
    295
    Rep Power
    46
    Originally Posted by BananaRepublic
    It may not be a case of two control having the same name but rather two objects. For example, if your procedure name has same name as the module, that would be an ambiguous name or something like that. So it's not merely a case of looking in the dropdown but also verifying that there is no other name conflict along different objects.
    I recreated the template, creating each object seperately, as as to avoid the possibility of a control array and the same thing happened. I also don't have any procedures with the same name. The only point it is mentioned in the code is when I reference the object itself.

    I've included the sub routine below:

    Code:
        ' Reset captions and heights
        ActiveDocument.lblItem1.Caption = ""
        ActiveDocument.lblCatcode1.Caption = ""
        ActiveDocument.lblQuant1.Caption = ""
        ActiveDocument.lblUnitcost1.Caption = ""
        ActiveDocument.lblDesc1.Caption = ""
                
        ActiveDocument.lblItem1.Height = "14"
        ActiveDocument.lblDesc1.Height = "14"
    
        Do Until x = rowcount + 1
         
            If x = 1 Then
    
                ' Populate boxes
                ActiveDocument.lblItem1.Caption = ActiveDocument.MailMerge.DataSource.DataFields("PROV_CCI1ST_1").Value
                ActiveDocument.lblCatcode1.Caption = ActiveDocument.MailMerge.DataSource.DataFields("PROV_CCI2ND_1").Value
                ActiveDocument.lblDesc1.Caption = ActiveDocument.MailMerge.DataSource.DataFields("PROV_CCI3RD_1").Value
                ActiveDocument.lblUnitcost1.Caption = ActiveDocument.MailMerge.DataSource.DataFields("UNIT_COST_1").Value
                ActiveDocument.lblQuant1.Caption = ActiveDocument.MailMerge.DataSource.DataFields("UNIT_QUANT_1").Value
    
                totalcost = totalcost + (ActiveDocument.MailMerge.DataSource.DataFields("UNIT_COST_1").Value * ActiveDocument.MailMerge.DataSource.DataFields("UNIT_QUANT_1").Value)
    
                ' Resize label if text will fill it
                If Len(ActiveDocument.MailMerge.DataSource.DataFields("PROV_CCI1ST_1").Value) > 16 Then
                
                    ActiveDocument.lblItem1.Height = "28"
                  
                End If
                
                If Len(ActiveDocument.MailMerge.DataSource.DataFields("PROV_CCI3RD_1").Value) > 25 Then
                
                    ActiveDocument.lblDesc1.Height = "28"
                    
                ElseIf Len(ActiveDocument.MailMerge.DataSource.DataFields("PROV_CCI3RD_1").Value) > 50 Then
                  
                    ActiveDocument.lblDesc1.Height = "45"
                    
                Else
                
                    ActiveDocument.lblDesc1.Height = "58"
                  
                End If
                
            Else
    
            
               ' STICK SOMETHING IN HERE
            
            
            End If
         
            ' Increase count by 1
            x = x + 1
          
        Loop
        
        ' Set totalcost into totalcost box
        ActiveDocument.lblTotalcost.Caption = "" + totalcost
  10. #6
  11. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2004
    Posts
    295
    Rep Power
    46
    Is anyone able to help with this at all? I've been on holiday so I've not had to deal with it but it's still causing me problems and I really can't figure out a solution.

IMN logo majestic logo threadwatch logo seochat tools logo