Open Entry Form to existing data

C

c8tz

Hi,
I have an entry form - I would like to be able to put in the ID and
Date and have the form showing the data for that.
Currently it's on open to Edit form - and shows the first record -

I would like to be able to type in the IDNO in the IDNo Text Box and
enter the date and it will show the corresponding data, thus it should
also load to a blank form.

Thanks
 
A

Allen Browne

Leave the form in edit mode, so that it loads all records.

Set the form's On Load property to:
[Event Procedure]
Then click the button button (...) beside the property.
Access opens the code window.

Set up the code like this, so that it goes to the new record:
Private Sub Form_Load()
If Not Me.NewRecord Then
RunCommand acCmdRecordsGotoNew
End If
End Sub

Now you need to add *unbound* text boxes where you enter the ID and the date
you want to find. Beside these 2 text boxes, add a command button that goes
to that record. Set the button's On Click property to:
[Event Procedure]
Click the button button (...) beside the property, and set up the code like
this:
Private Sub cmdGoto_Click()
Dim strWhere As String
If IsNull(Me.txtID) Or IsNull(Me.txtDate) Then
MsgBox "Enter both an ID and a date to find"
Else
If Me.Dirty Then Me.Dirty = False 'Save first
strWhere = "(IDNO = " & Me.txtID & ") AND ([MyDate] = " & _
Format(Me.txtDate, "\#mm\/dd\/yyyy\#") & ")"
With Me.RecordsetClone
.FindFirst strWhere
If .NoMatch Then
MsgBox "Not found"
Else
Me.Bookmark = .Bookmark
End If
End With
End If
End Sub

Substitute the name of your unbound text boxes, and the names of your
fields. (Hopefully Date is not the real field name.)
 

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

Similar Threads


Top