J
Judy Ward
I have an array that I use as the criteria for a query (the real array is
much longer):
IR_List(1) = "IR-7"
IR_List(2) = "IR-8"
IR_List(3) = "IR-9"
IR_List(4) = "IR-9.1"
But then I want to use these same designations as individual sheet names,
and Excel does not accept periods, spaces or dashes in a sheet name. So I
have been using a second array:
Sheet_List(1) = "IR_7"
Sheet_List(2) = "IR_8"
Sheet_List(3) = "IR_9"
Sheet_List(4) = "IR_9_1"
I thought it would be more efficient to use one array and convert the
characters so I wrote a function to do so:
Function ReplaceChars(ByRef strText As String)
Dim currLoc As Integer
Dim tmpChar As String
For currLoc = 1 To Len(strText)
tmpChar = Mid(strText, currLoc, 1)
If InStr(".", tmpChar) Or InStr("-", tmpChar) Or InStr(" ", tmpChar)
Then
' Replace with a "_"
Mid(strText, currLoc, 1) = "_"
End If
Next
ReplaceChars = strText
End Function
This function does replace the characters. But when I try to use it as part
of a SQL query replacing:
& "INTO " & sCnxn & "]." & Sheet_List(idx) _
with
& "INTO " & sCnxn & "]." & ReplaceChars(IR_List(idx)) _
does not work.
For some reason Sheet_List(idx) translates into IR-7
but ReplaceChars(IR_List(idx)) translates into "IR-7"
(quotes arount the string) and the query doesn't return any data.
If anyone can follow what I am trying to ask, I would really appreciate
knowing if there is something simple I am overlooking to get this to work
(not have quotes around ReplaceChars(IR_List(idx))).
Thank you,
Judy
much longer):
IR_List(1) = "IR-7"
IR_List(2) = "IR-8"
IR_List(3) = "IR-9"
IR_List(4) = "IR-9.1"
But then I want to use these same designations as individual sheet names,
and Excel does not accept periods, spaces or dashes in a sheet name. So I
have been using a second array:
Sheet_List(1) = "IR_7"
Sheet_List(2) = "IR_8"
Sheet_List(3) = "IR_9"
Sheet_List(4) = "IR_9_1"
I thought it would be more efficient to use one array and convert the
characters so I wrote a function to do so:
Function ReplaceChars(ByRef strText As String)
Dim currLoc As Integer
Dim tmpChar As String
For currLoc = 1 To Len(strText)
tmpChar = Mid(strText, currLoc, 1)
If InStr(".", tmpChar) Or InStr("-", tmpChar) Or InStr(" ", tmpChar)
Then
' Replace with a "_"
Mid(strText, currLoc, 1) = "_"
End If
Next
ReplaceChars = strText
End Function
This function does replace the characters. But when I try to use it as part
of a SQL query replacing:
& "INTO " & sCnxn & "]." & Sheet_List(idx) _
with
& "INTO " & sCnxn & "]." & ReplaceChars(IR_List(idx)) _
does not work.
For some reason Sheet_List(idx) translates into IR-7
but ReplaceChars(IR_List(idx)) translates into "IR-7"
(quotes arount the string) and the query doesn't return any data.
If anyone can follow what I am trying to ask, I would really appreciate
knowing if there is something simple I am overlooking to get this to work
(not have quotes around ReplaceChars(IR_List(idx))).
Thank you,
Judy