نوشته شده توسط
narpco
فقط یک سئوال این الان 3 تا فیلد رو جستجو میکنه با هم ......چطور بهش دستور اضافه کنیم برای 5 فیلد ......
نام شرکت
سال
ماه
کد پرسنل
شماره قرارداد
سلام
همون روش
قسمت if
برای هر کدوم که خواستید یک ifدیگه اضاف کنید
If Nz(Me.RCa_coname.Value, "") <> "" Then
strWhere = strWhere & "[RCa_coname] = " & Me.RCa_coname.Value & " AND "
End If
If Nz(Me.RCa_year.Value, "") <> "" Then
strWhere = strWhere & "[RCa_year] = " & Me.RCa_year.Value & " AND "
End If
'----------------------------------------
'other if
If Nz(Me.myfield4.Value, "") <> "" Then
strWhere = strWhere & "[myfield4] = " & Me.myfield4.Value & " AND "
End If
'endf
'-------------------------------------
If Nz(Me.RCa_mah.Value, "") <> "" Then
strWhere = strWhere & "[RCa_mah] = " & Me.RCa_mah.Value & " AND "
End If
همچنان بجای myfield4 اسم فیلد خودتون رو بگذارید
strWhere دیگه اضافه کنید.
اگر تکست باکس را نگاه کنید .دقیقا توجه میشین که داره اگر فیلد پر باشه در کد اعمال میکنه .
میخوایم تمام ایتمها رو با هم در یک خط جمع کنیم .(تک به تک نباشه .
اون 5 که اخر هم کم کرده از اخر تکست باکس اگر 5 رو بردارید یک " and " شامل دو اسپسیس قبل و بعد و سه حرف and رو برمیداره . چون اضاف میاد. در اخر
هر مرحله کد رو با یک and به strWhere اضاف میکنه .
strWhere=filter1 & " and "
strWhere=strWhere+filter2 & " and "
strWhere=strWhere+filter3 & " and "
strWhere=strWhere+filter4 & " and "
strWhere=strWhere+filter5 & " and "
نتیجه
strWhere= filter1 and filter2 and filter3 and filter4 and filter5 and
بعد حذف and آخری
strWhere= filter1 and filter2 and filter3 and filter4 and filter5
بعد اعمال فیلتر
filter=strWhere
یعنی در عمل
filter= filter1 and filter2 and filter3 and filter4 and filter5
برای خروج من این کد را گذاشتم .خطا نداد
Me.frm_morkhasi_sub.Form.Filter = ""
Me.frm_morkhasi_sub.Form.FilterOn = False
ضمنا گم بودید . نگران شدم.