|
▼masashi さん:
動的に クエリを作ってみました。
こちらは VBA での操作になります。
適当なモジュールに貼り付けて実行させると
QName で指定した名前のクエリができていると思います。
Sub 変数でクエリを作成()
'要参照 Microsoft DAO x.x Object Library
Dim TName As String
Dim QName As String
Dim QD As DAO.QueryDef
Dim SelSQL As String
Dim WheSQL As String
Dim strSQL As String
Dim Ijyo As Long
Dim Miman As Long
Dim i As Long
TName = "T_Temp" '元テーブル名
QName = "Q_Temp" '作成クエリ名
Ijyo = 20 '以上値
Miman = 25 '未満値
If DCount("*", "MSysObjects", "NAME = '" & QName & "'") Then _
DoCmd.DeleteObject acQuery, QName
For i = 1 To 5
SelSQL = SelSQL & TName & ".A" & i & ","
WheSQL = WheSQL & "(" & TName & ".A" & i & " >= " & Ijyo & " AND " _
& TName & ".A" & i & " < " & Miman & ") Or "
Next
SelSQL = Left(SelSQL, Len(SelSQL) - 1)
WheSQL = Left(WheSQL, Len(WheSQL) - 4)
strSQL = "SELECT " & TName & ".Model, " _
& SelSQL _
& " FROM " & TName _
& " WHERE " _
& WheSQL
Set QD = CurrentDb.CreateQueryDef(QName, strSQL)
Set QD = Nothing
End Sub
|
|