Retrievng a record in a form

  • Thread starter Thread starter red6000
  • Start date Start date
R

red6000

Hi,

I have a form which has 2 subforms both bound to tables.

The 'Data Entry' property for both is set to 'Yes' so the form opens with
both subforms having empty data.

What I would like is to be able to retrieve a record on 1 of the subforms:

Subform name is 'Timesheet' with 5 fields. I'd like to be able to retrieve
the record based on 2 criteria.

Now I know I need 2 text boxes to hold the criteria and then a command
button, but what code do I need to be able to retrieve the appropriate
record in the subform?

Many Thanks.
 
first, you need to set the subform's DataEntry property to No, otherwise you
won't be able to access existing records from that form. second, instead of
binding the form directly to the table, bind it to a query that is based on
the table. in the query design view, set criteria on the two fields you want
to use to select a record, as

[Forms]![NameOfMainForm]![TextboxControlName]

substitute the name of the main form, and the name of the first textbox
control; then use the same syntax to refer to the second textbox control, in
the criteria on the other field in the query.

third, add a command button to the main form. add code to the button's Click
event procedure, as

Me!SubformControlName.Form.Requery

substitute the correct name of the subform control (it may be different from
the name of the subform as it's listed in the database window).

now when you open the form, no records will be returned, but the user can
enter new records. to find an existing record in the table, enter the
criteria in the textbox controls on the main form, then click the command
button to requery the subform's RecordSource. if a matching record is found,
it will display in the subform. note that any newly entered records will
*not* display, unless they match the criteria.

hth
 

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

Back
Top