The suggest strings below do not return the correct
strings in the query expression: The first one
returns: '.' and the second returns: "."
Below is the full subroutine:
Private Sub Build_Bottom_Up_Ownership_Chains_Test()
Dim DB_Ownership As Database
Dim Table_Own_Relation, Table_Struct_Chains_TEMP As
DAO.Recordset
Dim QueryName, strSQLPS_Q_FieldNameXRef,
strWHEREPS_Q_FieldNameXRef, SearchField As String
Dim strQuery, strINSERT, strSELECT, strWHERE,
strFROM, strORDERBY As String
Dim ZeroLenStr, ConcatPeriodStr, CurrentLevel,
LevelNo, LevelNoLess_1 As String
On Error GoTo Err_Build_Bottom_Up_Ownership_Chains_Click
Set DB_Ownership = CurrentDb()
Set Table_Own_Relation = DB_Ownership.OpenRecordset
("Ownership Table - All Relationships", dbOpenTable)
Set Table_Struct_Chains_TEMP =
DB_Ownership.OpenRecordset("Ownership Structure Chains B-
UP - TEMP", dbOpenTable)
CurrentLevel = 2
If CurrentLevel < 10 Then LevelNo = "0" & Trim(Str
(CurrentLevel)) _
Else LevelNo = Trim(Str(CurrentLevel))
If (CurrentLevel - 1) < 10 Then LevelNoLess_1 = "0" &
Trim(Str(CurrentLevel - 1)) _
Else LevelNoLess_1 = Trim(Str(CurrentLevel - 1))
ConcatPeriodStr = " & ""."" & "
strSELECT = "SELECT [Ownership Structure Chains B- UP -
TEMP].*, [Ownership Table - All Relationships].[Direct
Owner ID] AS [Level " & LevelNo & " ID], " _
& "[Ownership Table - All Relationships].
[Direct Owner Name] AS [Level " & LevelNo & " Name], " _
& "[Ownership Table - All
Relationships].EffOwnPct AS [Level " & LevelNo & " %],
0.000000001 AS [Level " & LevelNo & " - Up %], " _
& "0.000000001 AS [Level " & LevelNo & " - Down
%], IIf(IsNull([Ownership Table - All Relationships]!
[Entity ID]) " _
& "Or [Ownership Table - All Relationships]!
[Entity ID]= """" ,Null," _
& "[Ownership Structure Chains B-UP - TEMP]!
[Level " & LevelNoLess_1 & " Owner Chain]" &
ConcatPeriodStr & "[Ownership Table - All Relationships]!
[Entity Owned Count]) " _
& "AS [Level " & LevelNo & " Owner Chain] INTO
[Ownership Structure Chains B-UP]"
strFROM = "FROM [Ownership Structure Chains B-UP -
TEMP] LEFT JOIN [Ownership Table - All Relationships]
ON " _
& "[Ownership Structure Chains B-UP - TEMP].
[Level " & LevelNoLess_1 & " ID] = [Ownership Table - All
Relationships].[Entity ID]"
strWHERE = "WHERE ((([Ownership Table - All
Relationships].[Entity ID]) <> ""zz_NON-AFF"" And
([Ownership Table - All Relationships].[Entity ID])
<> ""zz_AFF_Quest"" " _
& "And ([Ownership Table - All Relationships].
[Entity ID]) <> "".LACPOP"" And ([Ownership Table - All
Relationships].[Entity ID]) <> ""EOUTRS0459""))" _
& "OR ((([Ownership Table - All Relationships].
[Entity ID]) Is Null))"
strORDERBY = "ORDER BY [Ownership Structure Chains B-
UP - TEMP].[Entity ID], IIf(IsNull([Ownership Table - All
Relationships]![Entity ID]) " _
& "Or [Ownership Table - All Relationships]!
[Entity ID]="""",Null," _
& "[Ownership Structure Chains B-UP - TEMP]!
[Level " & LevelNoLess_1 & " Owner Chain]" & """."""
& "[Ownership Table - All Relationships]![Entity Owned
Count])"
CurrentDb.QueryDefs("Build Own Structure BUP - Levels
GT 01").sql = strSELECT & strFROM _
& strWHERE & strORDERBY & ";"
DoCmd.SetWarnings False
QueryName = "Build Own Structure BUP - Levels GT 01"
DoCmd.OpenQuery QueryName, acNormal, acReadOnly
Table_Own_Relation.Close
Table_Struct_Chains_TEMP.Close
Exit_Build_Bottom_Up_Ownership_Chains_Click:
DoCmd.SetWarnings True
Exit Sub
Err_Build_Bottom_Up_Ownership_Chains_Click:
MsgBox Err.Description
Resume Exit_Build_Bottom_Up_Ownership_Chains_Click
End Sub
-----Original Message-----
Try
" & '.' & "
Or
" & ""."" & "
I just tried the following and it appeared to do what
you want if I used either of the
above as the value of the constant ConcatPeriodStr.
Function Test3() As String
Const CurrentLevel = 222
Const ConcatPeriodStr = " & ""."" & "
Test3 = "IIf(IsNull([Ownership Table - All
Relationships]![Entity ID]) " _
& "Or [Ownership Table - All Relationships]![Entity ID] = """" ,Null," _
& "[Ownership Structure Chains B-UP - TEMP]![Level " &
CurrentLevel - 1 & " Owner Chain]"
& ConcatPeriodStr & "[Ownership Table - All
Relationships]![Entity Owned Count]) " _
& "AS [Level " & CurrentLevel & " Owner Chain]"
End Function
--
Wayne Morgan
Microsoft Access MVP
I am trying to build an SQL query string which
includes "&" as part of the string. The "&" is used as
part of an expression in the query. It keeps erroring out
at the "CurrentDb.QueryDefs" statement.
As it appears in query:
Level 2 Owner Chain: IIf(IsNull([Ownership Table - All
Relationships]![Entity ID]) Or [Ownership Table - All
Relationships]![Entity ID]="",Null,[Ownership Structure
Chains B-UP - TEMP]![Level 1 Owner Chain] & "." &
[Ownership Table - All Relationships]![Entity Owned Count])
The SQL query string build:
ConcatPeriodStr = "' & ""."" & '"
IIf(IsNull([Ownership Table - All Relationships]! [Entity
ID]) " _
& "Or [Ownership Table - All Relationships]![Entity ID]
= """" ,Null," _
& "[Ownership Structure Chains B-UP - TEMP]![Level " &
CurrentLevel - 1 & " Owner Chain]" & ConcatPeriodStr
& "[Ownership Table - All Relationships]![Entity Owned
Count]) " _
& "AS [Level " & CurrentLevel & " Owner Chain]
ConcatPeriodStr then equals: "' & "." & '"
Which returns: ' & "." & ' to the query expression, I
need it to appear as: & "." &
I don't want the single quotes.
No matter how I change "ConcatPeriodStr", I can not get
& "." & returned to the query expression.
HELP
.