Qlik Community

QlikView Scripting

Discussion Board for collaboration on QlikView Scripting.

Announcements
QlikView Fans! We’d love to hear from you.
Share your QlikView feedback with the product team… Click here to participate in our 5-minute survey.
Rules, plus terms and conditions, can be found here.
Not applicable

In a macro, fields with 8-bit names

Several of my fields have 8-bit names ("Année" is the French word for "year", for example).

It seems to be a problem when I try to access those fields in a VB macro by using ActiveDocument.Fields("Année").GetPossibleValues

Is there a proper way to access those fields or do I need to rename all my fields ?

8 Replies

Re: In a macro, fields with 8-bit names

One Solution in Excel for an export to *.txt, perhaps it's helpful

Public Const cLetters = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZäöüÄÖÜß"

Public Const cNumbers = "0123456789"

Public Const cWhiteSpaces = " " & vbCr & vbLf & vbTab

Public Const cSigns = """|!#$%&'()*+,-./0123456789:;<=>?@[\]^_`€Ø{}²³´–"

Public Function Filter(str As String, ByVal z As Long, ByVal s As Byte) As String

Dim i As Long

For i = 1 To Len(str)

    If InStr(1, cLetters & cNumbers & cWhiteSpaces & cSigns & Chr(133) & Chr(160), Mid$(str, i, 1), vbTextCompare) Then

        Filter = Filter & Mid$(str, i, 1)

    Else

        Filter = Filter & "?"

        'MsgBox "Zeile " & z & Chr(10) & "Spalte " & s & Chr(10) & "Zeichen: " & Mid$(str, i, 1) & " - Code: " & Asc(Mid$(str, i, 1))

    End If

Next i

 

End Function

Not applicable

Re: In a macro, fields with 8-bit names

Thanks Marcus for your transform function but my problem is that I cannot access the fields of the table "Année" by calling ActiveDocument.Fields("Annee").GetPossibleValues

MVP
MVP

Re: In a macro, fields with 8-bit names

Hi

Is your problem trying to enter accented characters in the editor(s)?

You can enter accented characters in the script and module editors using the ALT key. For example é can be entered by holding down the ALT key and typing 0233. You could also select and copy the characters from the Windows character map (charmap.exe).

Hope that helps

Jonathan

Logic will get you from a to b. Imagination will take you everywhere. - A Einstein
Not applicable

Re: In a macro, fields with 8-bit names

Thanks Jonathan, but no: it's not a proble of typing the letters.

My proble is that when I try to get values of the table "DateCde" it works with :

    Set objSelected = ActiveDocument.Fields("DateCde").GetPossibleValues

    Date= objSelected.item(0).Text

While I cannot get the year in table "AnnéeCde" :

    Set objSelected = ActiveDocument.Fields("AnnéeCde").GetPossibleValues

    Date= objSelected.item(0).Text

I am quite reluctant in changing (almost) all my table names...

Re: In a macro, fields with 8-bit names

Solution?

put your field "AnnéeCde" in Listbox or Tablebox and read there the possible Values

flipside
Valued Contributor II

Re: In a macro, fields with 8-bit names

I've tried to replicate this but your code seems to work fine for me (QV10 SR4) so not sure exactly where the issue lies.

That said, a way round it might be to reference the field using its integer field reference, like this ...

set fld=ActiveDocument.GetFieldDescriptions(7)

Set objSelected = ActiveDocument.Fields(fld.Name).GetPossibleValues

For  i = 0 to objSelected.Count-1

MsgBox(objSelected.item(i).Text)

next

The trick will be to identify what the field reference actually is using this ...

set flddescs = ActiveDocument.GetFieldDescriptions

for i = 0 to flddescs.Count - 1

    fdesc = flddescs(i)

        msgbox(fdesc.Name & " is field ref: " & i)

next

The next problem is: Will the value stay at what you find? - probably not if you insert new fields in your script, so therefore you will need to loop through all fields and set a variable when you find the one you want, something like ...

set flddescs = ActiveDocument.GetFieldDescriptions

for i = 0 to flddescs.Count - 1

    fdesc = flddescs(i)

        if fdesc.Name ="AnnéeCde" then set fldcode=i

    

        if fdesc.Name ="AnnéeCde" then

          fldcode=i

        end if

next

and use fldcode as the parameter in the GetFieldDescriptions.

flipside

Not applicable

Re: In a macro, fields with 8-bit names

Thank you flipside for the useful code that enables to get all the names of the fields. I tried to do this but did not succeed in.

Actually, my problem is solved and was not due to 8-bits name (but to an empty field)

Sorry for this and thanks for your help!

flipside
Valued Contributor II

Re: In a macro, fields with 8-bit names

Glad you got it sorted.

I've corrected my dodgy code above in case it is of any use to anyone else.

Community Browser