find record on load

  • Thread starter FrustratedAccessUser
  • Start date
F

FrustratedAccessUser

I have a main form (Plan Status) with a subform (z_Plan Status). On the
subform there is a command button that opens another form depending on the
Project Number field in the main form. The form that opens has the following
code in the on load event:

Private Sub Form_Load()

If Not IsNull(Forms("Plan Status").[ProjectNumber]) Then
If Me.Dirty Then 'Save before move.
Me.Dirty = False
End If

strWhere = "[Project_Number] = " & Forms("Plan
Status").[ProjectNumber]
With Me.RecordsetClone
.FindFirst strWhere
If .NoMatch Then
DoCmd.GoToRecord , , acNewRec
Me.Project_Number = Forms("Plan Status").ProjectNumber
Else
Me.Bookmark = .Bookmark
End If
End With
End If

End Sub

What I'm trying to do is to have the form open to the record matching the
project number field. And if there isn't a matching record already, I would
like it to create one and fill in a field on the record. The problem with
this code, is it assumes that there is never a match and always puts in a new
record (the new record command works exactly how I want it to). Any ideas on
the find record portion?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top