Full Version: Commnad button, creating serach event procedure
UtterAccess Discussion Forums > Microsoft® Access > Access Forms
Buckeye_FAN_2010
Bone, has helped me out a lot. What I'm trying to accomplished is to allow a user to enter an keyrec, distro number or trailer number and search exact comments related to that specific value. I downloaded a template as premsis to help me. The problem is I receive a "You can't assigne a value to this object" error. The main form is called "Browse All Issues FADC". The exact code is listed below. Attached is the database. If someone has another database example or directions I could use it.



Private Sub Search_Click()
Dim strWhere As String
Dim strError As String

strWhere = "1=1"

' If Distro Number By
If Not IsNull(Me.Distro_Number) Then
'Add the predicate
strWhere = strWhere & " AND " & "FADC Mangers Comments.Distro Number = " & Me.Distro_Number & ""
End If

' If Keyrec
If Nz(Me.Keyrec) <> "" Then
'Add it to the predicate - exact match
strWhere = strWhere & " AND " & "FADC Mangers Comments.Keyrec = '" & Me.Keyrec & "'"
End If

' If Comment
If Nz(Me.Comment) <> "" Then
' Add it to the predicate - match on leading characters
strWhere = strWhere & " AND " & "FADC Mangers Comments.Comment Like '*" & Me.Comment & "*'"
End If

If strError <> "" Then
MsgBox strError
Else
'DoCmd.OpenForm "Browse All Issues FADC", acFormDS, , strWhere, acFormEdit, acWindowNormal
If Not Me.FormFooter.Visible Then
Me.FormFooter.Visible = True
DoCmd.MoveSize Height:=Me.WindowHeight + Me.FormFooter.Height
End If
Me.Browse_All_Issues_FADC.Form.Filter = strWhere
Me.Browse_All_Issues_FADC.Form.FilterOn = True
End If
End Sub
HiTechCoach
It appears you table (or query) has spaces in the name. You must wrap any object bname that has spaces with [ and ]

Try changing your code to be like:

strWhere = strWhere & " AND " & "[FADC Mangers Comments].Distro Number = " & Me.Distro_Number & ""

I added: { and ] araond the table (or query) name.
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.