February 3rd, 2010, 12:21 PM
VBA problem - Ambiguous name detected
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.
February 10th, 2010, 06:38 AM
Is anyone able to help with this? Im happy to give anymore information which may be of use.
February 11th, 2010, 03:41 AM
I think you have copy and pasted the controls resulting in a control array.
February 13th, 2010, 02:25 PM
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.
February 18th, 2010, 11:24 AM
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.
Originally Posted by BananaRepublic
I've included the sub routine below:
' 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"
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"
ActiveDocument.lblDesc1.Height = "58"
' STICK SOMETHING IN HERE
' Increase count by 1
x = x + 1
' Set totalcost into totalcost box
ActiveDocument.lblTotalcost.Caption = "£" + totalcost
March 19th, 2010, 05:22 AM
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.