Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Wanet Telecoms Ltd on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

'%' Causes Errors When Creating Field Names in Code

Status
Not open for further replies.

laakins

MIS
Feb 7, 2003
43
US
I am dynamically creating a table where the field names will change everytime the code is ran. My issue is there are several times where the name passed through will contain the '%' character (and possibly other harmful characters). This causes my code to error out. I would prefer not to have to find every '%' and replacing it with a "safe" character. Any other solutions?

Set fldRptField = tdfReport.CreateField(fldAcctField.Name & " Count", fldAcctField.Type, fldAcctField.Size)
tdfReport.Fields.Append fldRptField

the fldAcctField is a field in another table who's source was originally an Excel Spreadsheet.

Thanks.
 
I don't know if it will work but try this:
Code:
Set fldRptField = tdfReport.CreateField("[" & fldAcctField.Name & " Count]", fldAcctField.Type, fldAcctField.Size)
tdfReport.Fields.Append fldRptField

[pc2]
 
mp9
Would'nt that add the disallowed characters [ and ] to the field name?

laakins
I have tried field names with % and they work for me. However, if this is a numeric field, there will be no field size. I think you need to check for this and change the line accordingly to:
[tt]Set fldRptField = tdfReport.CreateField("[" & fldAcctField.Name & " Count]", fldAcctField.Type)[/tt]

[ponder]
 
I figured out my issue. It was not the characters passed through but the length of the string. Only 64 Characters are allowed and with my adding 'Count' at the end made it more than 64. I will have to add Count later on in my process. Thanks guys.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top