Searhing Records problems
Dear All,
I encounter some problems in searching.
First, i have create a edit form which have 5 fileds and contain a button search. User can click on the search button to check the fields they entered is in the personal details form or not.
PS. In the personal details form which contain a subform of cert details.
After they enter the field in edit form , the problems happened. I don't know why the field which is in the subform that i needed to enter one more time in order to get in the personal details form but it shows all the records.
Can anyone tell me what can i do??
Here is the code of edit form
Option Compare Database
Dim t
Private Sub Find_Click()
Dim db As DAO.Database, rcd As DAO.Recordset
Dim count As Integer
gstrwherebook = ""
t = ""
count = 0
'in the main form of personal detail
If Not IsNull(Me!ID) Then
gstrwherebook = "[ID] like '" & Me!ID & "'"
End If
'in the subform of personal details
If Not IsNull(Me!CertNo) Then
If gstrwherebook = "" Then
gstrwherebook = "[cert no] like '" & Me!CertNo & "'"
Else
gstrwherebook = gstrwherebook & "AND [cert no] like '" & Me!CertNo & "'"
End If
End If
'in the subform of personal details
For Each varItm In Me![type].ItemsSelected
t = t & " or [type] Like '" & Me![type].ItemData(varItm) & "'"
count = count + 1
Next varItm
If t <> "" Then
t = Right(t, Len(t) - 4)
End If
If count <> 0 Then
If gstrwherebook = "" Then
gstrwherebook = gstrwherebook & t
Else
gstrwherebook = gstrwherebook & "AND " & gstrwherebook & t
End If
End If
'in the subform of personal details
If Not IsNull(Me!location) Then
If gstrwherebook = "" Then
gstrwherebook = "[location] like '" & Me!location & "'"
Else
gstrwherebook = gstrwherebook & "AND [location] like '" & Me!location & "'"
End If
End If
DoCmd.OpenForm "personal details", acNormal, , gstrwherebook
DoCmd.Close acForm, Me.Name
End Sub
The cod maybe worng because i'm the beginner to write vba and these book is just find out from books and i modify it!! So if you find it has problems, please tell me to correct it!! Thanks!!
Please help me, Thanks a lot!!!
|