Skip to main content



Drawing value from Excel with vb-script dependant on internal drop down



  • Avatar
    Peter Thane

    I think the issue could be one of two things or a combination of both, namely when the VB is being run during the printing process and as you are performing a full textual comparison. 

     I would suggest adding the VB to the text field itself and configuring it as an Event Controlled Script set to (probably) OnNewRecord or else OnPostPrompt so that the VB runs at that time only. You may also want to use the InStr command instead of the full text comparison as this will fail if the pattern doesn't match in full, such as if there is a spurious extra character in the field, such as an extra space.  

    I assume Spannung maybe another field in the database in which case you can amend the 1st line to link to this directly by typing on line 1 Value = and then double clicking on the database field name. For my sample I have just added a drop down list with either the 100-120V.... and the 220-240V.... as selectable at print time which in turn populates a Spannung named field, whilst my database has values of German and USA for the Leistung and Leistung USA fields. 

    My VB is as follows: 

    Value = Format.NamedSubStrings("Spannung").Value

    If Instr(Value,100) > 0 then 
    Value = Field("[VBVoltage].[VBVoltage].[Geraeteetikett_221207.Geraete.Leistung]")
    Elseif Instr(Value,220) > 0 then
    Value = Field("[VBVoltage].[VBVoltage].[Geraeteetikett_221207.Geraete.Leistung USA]")
    else Value = " "
    end if 

    Value = Value

    As you can see this is set to look for either the 100 or 220 voltages and from this determines which database field to print.

    I hope this helps

  • Avatar
    Robert Saurer

    Hello Peter,

    thank you very much for pointing me into the right direction. I wasn't so far away, but it still took me 2 days (not full time!) to get it right!

    The clou was to make a named data source "Spannung" and put the vb-script into "OnNewRecord".

    BTW I also had to make a named data source for "Leistung" and "Leistung USA" otherwise I sometimes got an error message.

    I decided to stay with the full text comparison.

    Value = Format.NamedSubStrings("Spannung").Value
    if Value = "100-120 V  50-60 Hz" or Value = "3x 200-220 V  50-60 Hz" then
       Value = Format.NamedSubStrings("LeistungUS").Value
       Value = Format.NamedSubStrings("LeistungEU").Value
    end if



Please sign in to leave a comment.