I would do it a little differently. It will make the coding easier.
What I would do is find the date in the table, if it is there and pass the
date to the form using the OpenArgs argument of the OpenForm method. If The
date is not in the table, I would pass a Null to the form. Then in the
form's (the form you are opening) Load event, check the form's OpenArgs
property and navigate to the record if there is a date or create a new record
if there is no date:
Code for the Command Button:
Private Sub OpenForm_Click()
Dim varOpenArg As Variant
varOpenArg = DLookup("[TheDateField], "YourTableName", "[TheDateField] =
#" & Date() & "#"
If Not IsNull(varOpenArg) Then
varOpenArg = CStr(varOpenARg)
End If
DoCmd.OpenForm "TheOtherFormName", , , , , , varOpenArg
End Sub
Code for the other form's Load Event:
If IsNull(Me.OpenARgs) Then
DoCmd.GoToRecord acDataForm, Me.Name, acNewRec
Else
With Me.RecordsetClone
.FindFirst "[TheDateField] = #" & CDate(Me.OpenArgs) & "#"
If Not .NoMatch Then
Me.Bookmark = .Bookmark
End IF
End With
End If
--
Dave Hargis, Microsoft Access MVP
Chuck216 said:
Hi
I need help with some code. What I want to do is, when a command button is
clicked on a form I want it to look for a record with today’s date and open
that record in another form, if there is no record with today’s date I want
it to create one and open it in another form
As always any help is greatly appreciated.
Thanks
Chuck