Go to Record on Open

N

Neil Cash

I have a main form with a subform on it. Within the subform I have a command
button that opens another form depending on what the value of the combo box
next to it contains. What I would like for the opened form to do, is to go
to a record that matches a field in the main form [Project Number]. And if
one doesn't exist, I'd like it to create a new record with the Project Number
filled in from the main form. I've tried this goto record command thus far
to go to the record containing the Project Number:

Dim strCriteria As String
Dim rs As Recordset

strCriteria = "[Project_Number] = " & Forms("Plan Status").[ProjectNumber]
Set rs = Me.RecordsetClone
rs.FindFirst strCriteria

If rs.NoMatch Then
DoCmd.GoToRecord , , acNewRec
Me.Project_Number = Forms("Plan Status").ProjectNumber
Else
Me.Bookmark = rs.Bookmark
End If

rs.Close
Set rs = Nothing

It does exactly what I want it to with a new record, except it inserts a new
record every time, despite the fact that there is a match. Any ideas?
Thanks in advance.

Neil
 

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