実行エラー 3075:クエリ式`作成日 の間#2010/10/01# AND #2010/10/30#の構文エラー:演算子というエラーの処理をどうすればいいか分かりませんので教えてほしいです。
Private Sub cmdFilter_Click()
Dim strSQL As String
Dim strCriteria As String
With Me
If Len(.cboFieldName) <> 0 Then
If Len(.cboCondition) <> 0 Then
strCriteria = BuildCriteria(.cboFieldName.Column(0), _
.cboFieldName.Column(1), .cboCondition, _
Nz(.txtValue1), Nz(.txtValue2))
End If
End If
End With
With Me
ここはエラー→ .Filter = strCriteria
.FilterOn = True
.Requery
End With
Private Function BuildCriteria(strFieldName As String, _
intType As Integer, _
strCondition As String, _
varValue1 As Variant, _
Optional varValue2 As Variant) As String
Dim fBetween As Boolean
Dim fLike As Boolean
Dim strCriteria As String
Const conQuotes = """"
fBetween = IIf(InStr(strCondition, "の間") > 0, _
True, False)
fLike = IIf(InStr(strCondition, "類似") > 0, _
True, False)
strCriteria = strFieldName & " "
Select Case intType
Case dbText, dbMemo
If InStr(1, varValue1, "*") > 0 Then
strCriteria = strCriteria _
& " Like " & conQuotes & varValue1 & conQuotes
Else
If fLike Then
strCriteria = strCriteria & " 類似 " _
& conQuotes & "*" & varValue1 & "*" & conQuotes
Else
strCriteria = strCriteria & strCondition _
& " " & conQuotes & varValue1 & conQuotes
End If
End If
Case dbInteger, dbLong, dbCurrency, dbDouble, dbSingle
If fBetween Then
strCriteria = strCriteria _
& strCondition & " " & varValue1 & " AND " & varValue2
Else
strCriteria = strCriteria _
& strCondition & " " & varValue1
End If
Case dbDate
If fBetween Then
strCriteria = strCriteria & strCondition _
& " #" & Format(varValue1, "yyyy/mm/dd") & "# AND #" _
& Format(varValue2, "yyyy/mm/dd") & "#"
Else
strCriteria
No.4ベストアンサー
- 回答日時:
#1、#2です。
cboConditionに元々はLIKE、BETWEENというキーワードが入っていたが、
それを「類似」と「の間」に変更した、ということでしょうか。
本来はキーワードのBETWEENをstrConditionに渡すということであったならば
>Case dbDate
>If fBetween Then
>strCriteria = strCriteria & strCondition _
>& " #" & Format(varValue1, "yyyy/mm/dd") & "# AND #" _
>& Format(varValue2, "yyyy/mm/dd") & "#"
において、
>strCriteria = strCriteria & strCondition _
のところを、
strCriteria = strCriteria & " Between"_
でいいのでは、と思います。"" の中のBetweenの
前は半角空けておきます。
これで、#1で述べましたようにMsgBoxでstrCriteria
の中身が、
作成日 Between #2010/10/01# AND #2010/10/30#
となっていればいいのではと思います。
また、他の
>Case dbInteger, dbLong, dbCurrency, dbDouble, dbSingl
の場合も同様だと思いますが。
No.3
- 回答日時:
FUNCTION内で定義している
「strCondition」にどんな値が入るのか教えてほしいです。
関係しているかもしれません。
>If fLike Then
>strCriteria = strCriteria & " 類似 " _
「類似」には使われていませんが
他では使われています。
>strCriteria = strCriteria & strCondition _
おかしいときは、
途中にブレイクポイントをおいてデバッグするとか
メッセージボックスを追記して値がどうなっているか見る。
こういうことをしないと自力で解決できなくなりますから、
なぜおかしいか以前にやり方を聞く方がいいですね。
No.2
- 回答日時:
エラーの、
の間#2010/10/01# AND #2010/10/30#
は、本来
Between #2010/10/01# AND #2010/10/30#
になるのが、Between の代わりに 「の間」 が
演算子として入ってしまっているからではと思いますが。
If fBetween Then
strCriteria = strCriteria & strCondition _
& " #" & Format(varValue1, "yyyy/mm/dd") & "# AND #" _
& Format(varValue2, "yyyy/mm/dd") & "#"
のところで、Betweenが入るのは、strConditionの
ところですか。あるいは、
strCriteria = strCriteria & strCondition & "Between"_
とするのですか。
No.1
- 回答日時:
コードが途中掲載なので、思いついたことだけ。
(1)
With Me
ここはエラー→ .Filter = strCriteria
.FilterOn = True
.Requery
End With
の部分をコメントアウトして、変わりに
MsgBox strCriteria
をいれて、strCriteria の内容を確認
してみては。
(2)
#" & Format(varValue1, "yyyy/mm/dd") & "#
などを、
'" & Format(varValue1, "yyyy/mm/dd") & "'
にしてみるとか。
(3)
あるいは、txtValue1とtxtValue2の値の
対象となるレコードのフィールドなりが
テキスト型ならば、型を変更する。
あるいは、(2)をCaDate、Formatで
変更する。
(4)
BuildCriteriaの他の引数にNullがないか。
この回答への補足
すみません、これは全部のコードです。元々は行けているんですが条件のリストボックスの中にBETWEENとLIKEという条件があって、私は「の間」と「類似」に変わりました。そこでこのエラーに出てしまったんです。類似という条件でうまく検索できますが「の間」だけではいけてないです
txtValue1=ChangeProperty("cmdFilter")
Private Function BuildCriteria(strFieldName As String, _
intType As Integer, _
strCondition As String, _
varValue1 As Variant, _
Optional varValue2 As Variant) As String
Dim fBetween As Boolean
Dim fLike As Boolean
Dim strCriteria As String
Const conQuotes = """"
fBetween = IIf(InStr(strCondition, "の間") > 0, _
True, False)
fLike = IIf(InStr(strCondition, "類似") > 0, _
True, False)
strCriteria = strFieldName & " "
Select Case intType
Case dbText, dbMemo
If InStr(1, varValue1, "*") > 0 Then
strCriteria = strCriteria _
& " Like " & conQuotes & varValue1 & conQuotes
Else
If fLike Then
strCriteria = strCriteria & " Like " _
& conQuotes & "*" & varValue1 & "*" & conQuotes
Else
strCriteria = strCriteria & strCondition _
& " " & conQuotes & varValue1 & conQuotes
End If
End If
Case dbInteger, dbLong, dbCurrency, dbDouble, dbSingle
If fBetween Then
strCriteria = strCriteria _
& strCondition & " " & varValue1 & " AND " & varValue2
Else
strCriteria = strCriteria _
& strCondition & " " & varValue1
End If
Case dbDate
If fBetween Then
strCriteria = strCriteria & strCondition _
& " #" & Format(varValue1, "yyyy/mm/dd") & "# AND #" _
& Format(varValue2, "yyyy/mm/dd") & "#"
Else
strCriteria = strCriteria _
& strCondition & " #" & Format(varValue1, "yyyy/mm/dd") & "#"
End If
Case Else
strCriteria = strCriteria _
& strCondition & " " & varValue1
End Select
BuildCriteria = strCriteria
End Function
お探しのQ&Aが見つからない時は、教えて!gooで質問しましょう!
このQ&Aを見た人はこんなQ&Aも見ています
-
都道府県穴埋めゲーム
都道府県の名前を1人1つずつ投稿してください。全ての都道府県が出たら締め切ります!
-
フォロワー20万人のアカウントであなたのあるあるを披露してみませんか?
あなたが普段思っている「これまだ誰も言ってなかったけど共感されるだろうな」というあるあるを教えてください
-
映画のエンドロール観る派?観ない派?
映画が終わった後、すぐに席を立って帰る方もちらほら見かけます。皆さんはエンドロールの最後まで観ていきますか?
-
海外旅行から帰ってきたら、まず何を食べる?
帰国して1番食べたくなるもの、食べたくなるだろうなと思うもの、皆さんはありますか?
-
天使と悪魔選手権
悪魔がこんなささやきをしていたら、天使のあなたはなんと言って止めますか?
-
Access2010 「演算子がありません」エラー
その他(データベース)
関連するカテゴリからQ&Aを探す
おすすめ情報
- ・漫画をレンタルでお得に読める!
- ・人生のプチ美学を教えてください!!
- ・10秒目をつむったら…
- ・あなたの習慣について教えてください!!
- ・牛、豚、鶏、どれか一つ食べられなくなるとしたら?
- ・【大喜利】【投稿~9/18】 おとぎ話『桃太郎』の知られざるエピソード
- ・街中で見かけて「グッときた人」の思い出
- ・「一気に最後まで読んだ」本、教えて下さい!
- ・幼稚園時代「何組」でしたか?
- ・激凹みから立ち直る方法
- ・1つだけ過去を変えられるとしたら?
- ・【あるあるbot連動企画】あるあるbotに投稿したけど採用されなかったあるある募集
- ・【あるあるbot連動企画】フォロワー20万人のアカウントであなたのあるあるを披露してみませんか?
- ・映画のエンドロール観る派?観ない派?
- ・海外旅行から帰ってきたら、まず何を食べる?
- ・誕生日にもらった意外なもの
- ・天使と悪魔選手権
- ・ちょっと先の未来クイズ第2問
- ・【大喜利】【投稿~9/7】 ロボットの住む世界で流行ってる罰ゲームとは?
- ・推しミネラルウォーターはありますか?
- ・都道府県穴埋めゲーム
- ・この人頭いいなと思ったエピソード
- ・準・究極の選択
このQ&Aを見た人がよく見るQ&A
デイリーランキングこのカテゴリの人気デイリーQ&Aランキング
-
to_date使用時に発生するエラー...
-
SQL*PLUSでの分秒までの表示の仕方
-
日付型カラムへのデータINSERT
-
SQL*Loader フォーマット変換...
-
実行エラー 3075:クエリ式`作...
-
SQL*Loaderでのsysdate使用
-
日付の範囲検索がしたい
-
date型のインデックス
-
Access 日付けについての関数
-
Access VBAで行ラベルが定義さ...
-
Accessのマクロでモジュールを...
-
callで順に実行されるプロシー...
-
今日の日付が入った行のデータ...
-
SQL*Plusの終了はquit?exit?
-
PL/SQLについて
-
Statement ignored というエラー
-
エクセルVBAでUserFormを起動し...
-
sqlplusでヘッダーが付かない
-
Accessの数値から時間に変換す...
-
PL/SQLでSPOOLさせたいのですが...
マンスリーランキングこのカテゴリの人気マンスリーQ&Aランキング
-
SQL*Loaderでのsysdate使用
-
SQL*Loader フォーマット変換...
-
日付型カラムへのデータINSERT
-
DB2でのシステム日付のinsert、...
-
(日付 - 日付)/数値
-
SQL*PLUSでの分秒までの表示の仕方
-
SQL Server で 翌月10日を取...
-
エクセル上の 2017/10/27 7:01...
-
SQLエラーについて
-
ALTER SESSIONについて
-
SQL Sever での日付の差の求め...
-
「年月」のみの文字列フィール...
-
EXCELでの時間計算(休憩時間の...
-
to_date使用時に発生するエラー...
-
date型のインデックス
-
実行エラー 3075:クエリ式`作...
-
literal does not match format...
-
日付の範囲検索がしたい
-
date '0001-01-01'からの日数
-
PL/SQL パッケージでのプロンプ...
おすすめ情報