Full Version: I Am Having Trouble With My Code For Search
UtterAccess Forums > Microsoft® Access > Access Forms
wornout
I have a main form and a sub form
the problem I am having is with the code on the sub form it debugs and says object variable or with block variable not set and highlights Me.Parent.Recordset.FindFirst strSearch
and I dont know why below is the full bit of code
CODE
Private Sub Form_Current()

  Dim pk_field As String, pk_tbox As Control
  Dim primaryKey As String, strSearch As String

  Set pk_tbox = Me.ClientNOcomp 'textbox containing primary key *
  pk_field = "ClientNOcomp " 'primary key field name *"

  primaryKey = Nz(pk_tbox.Value, 0) 'change value to 0 if null
  pk_field = "[" & pk_field & "]" 'enclose field name with brackets

  If primaryKey <> 0 Then 'if not null (or not a new record)
    strSearch = pk_field & "=" & primaryKey

    Me.Parent.Recordset.FindFirst strSearch  'This is the bit it highlights yellow
  Else
     Me.Parent.Form.Recordset.AddNew
  End If

End Sub

cheekybuddha
Hi,

Try:
CODE
' ...
    Me.Parent.Form.Recordset.FindFirst strSearch
' ...

(You seem to have remembered the .Form reference in the line below!)

hth,

d
This is a "lo-fi" version of UA. To view the full version with more information, formatting and images, please click here.