質問編集履歴

3

修正

2019/07/03 01:44

投稿

退会済みユーザー
test CHANGED
File without changes
test CHANGED
@@ -289,3 +289,5 @@
289
289
  End Sub
290
290
 
291
291
  ```
292
+
293
+ ※wFilter はグローバル変数です(String)

2

修正

2019/07/03 01:44

投稿

退会済みユーザー
test CHANGED
File without changes
test CHANGED
@@ -92,12 +92,10 @@
92
92
 
93
93
 
94
94
 
95
-
95
+ ##追記
96
96
 
97
97
  ↓sazi さんの助言のもと
98
98
 
99
- ##追記
100
-
101
99
  ```VBA
102
100
 
103
101
  Private Sub Button_Search_Click()

1

追記

2019/07/03 01:42

投稿

退会済みユーザー
test CHANGED
File without changes
test CHANGED
@@ -89,3 +89,205 @@
89
89
 
90
90
 
91
91
  よろしくお願いします
92
+
93
+
94
+
95
+
96
+
97
+ ↓sazi さんの助言のもと
98
+
99
+ ##追記
100
+
101
+ ```VBA
102
+
103
+ Private Sub Button_Search_Click()
104
+
105
+
106
+
107
+ '検索欄が空のときフィルタをかけない
108
+
109
+
110
+
111
+ If Me!Text_ProductCode = "" And Me!Text_ProductName = "" And Me!Text_Cost = "" And Me!Text_Cost2 = "" Then
112
+
113
+ Exit Sub
114
+
115
+ Else
116
+
117
+
118
+
119
+ 'フィルタをかける
120
+
121
+
122
+
123
+ wFilter = "F_DeleteFlag = False "
124
+
125
+
126
+
127
+ '商品コード
128
+
129
+ If Nz(Me!Text_ProductCode, "") <> "" Then
130
+
131
+ wFilter = wFilter & " and F_ProductCode like ""*" & Text_ProductCode & "*"""
132
+
133
+ Else
134
+
135
+ End If
136
+
137
+
138
+
139
+ '商品名
140
+
141
+ If Nz(Me!Text_ProductName, "") <> "" Then
142
+
143
+ wFilter = wFilter & " and F_ProductName like ""*" & Text_ProductName & "*"""
144
+
145
+ Else
146
+
147
+ End If
148
+
149
+
150
+
151
+ '単価
152
+
153
+ If Nz(Me!Text_Cost, "") <> "" And Nz(Me!Text_Cost2, "") <> "" Then
154
+
155
+ wFilter = wFilter & " and F_Cost <= Text_Cost2 " & " and F_Cost >= Text_Cost"
156
+
157
+ ElseIf Nz(Me!Text_Cost, "") = "" Then
158
+
159
+ wFilter = wFilter & " and F_Cost <= Text_Cost2"
160
+
161
+ ElseIf Nz(Me!Text_Cost2, "") = "" Then
162
+
163
+ wFilter = wFilter & " and F_Cost >= Text_Cost"
164
+
165
+ End If
166
+
167
+
168
+
169
+ With Me!Sub_ProductMaster.Form
170
+
171
+ .Filter = wFilter
172
+
173
+ .FilterOn = True
174
+
175
+ End With
176
+
177
+
178
+
179
+ '件数更新
180
+
181
+
182
+
183
+ TOTAL = DCount("F_ProductCode", "T_Product", Me!Sub_ProductMaster.Form.Filter)
184
+
185
+
186
+
187
+ Me.Text_Num = TOTAL + "件"
188
+
189
+ End If
190
+
191
+
192
+
193
+ End Sub
194
+
195
+ ```
196
+
197
+ ↓hatena19 さん助言のもと
198
+
199
+ ```VBA
200
+
201
+ Private Sub Button_Search_Click()
202
+
203
+
204
+
205
+ '検索欄が空のときフィルタをかけない
206
+
207
+
208
+
209
+ If Me!Text_ProductCode = "" And Me!Text_ProductName = "" And Me!Text_Cost = "" And Me!Text_Cost2 = "" Then
210
+
211
+ Exit Sub
212
+
213
+ Else
214
+
215
+
216
+
217
+ 'フィルタをかける
218
+
219
+
220
+
221
+ wFilter = "F_DeleteFlag = False "
222
+
223
+
224
+
225
+ '商品コード
226
+
227
+ If Nz(Me!Text_ProductCode, "") = "" Then
228
+
229
+ Else
230
+
231
+ wFilter = wFilter + "and F_ProductCode like ""*" & Text_ProductCode & "*"""
232
+
233
+ End If
234
+
235
+
236
+
237
+ '商品名
238
+
239
+ If Nz(Me!Text_ProductName, "") = "" Then
240
+
241
+ Else
242
+
243
+ wFilter = wFilter + "and F_ProductName like ""*" & Text_ProductName & "*"""
244
+
245
+ End If
246
+
247
+
248
+
249
+ '単価
250
+
251
+ If Nz(Me!Text_Cost, "") <> "" Then
252
+
253
+ wFliter = wFilter & "and F_Cost >= " & Me.Text_Cost
254
+
255
+ End If
256
+
257
+
258
+
259
+ If Nz(Me!Text_Cost2, "") = "" Then
260
+
261
+ wFilter = wFilter & "and F_Cost <= " & Me.Text_Cost2
262
+
263
+ End If
264
+
265
+
266
+
267
+ With Me!Sub_ProductMaster.Form
268
+
269
+ .Filter = wFilter
270
+
271
+ .FilterOn = True
272
+
273
+ End With
274
+
275
+
276
+
277
+ '件数更新
278
+
279
+
280
+
281
+ TOTAL = DCount("F_ProductCode", "T_Product", Me!Sub_ProductMaster.Form.Filter)
282
+
283
+
284
+
285
+ Me.Text_Num = TOTAL + "件"
286
+
287
+ End If
288
+
289
+
290
+
291
+ End Sub
292
+
293
+ ```