Bindiing controls to recordset???

  • Thread starter Thread starter TC
  • Start date Start date
T

TC

In Access 97 & below you can not bind the controls of a form onto the fields
of a manually generated recordset. You can only bind them to the fields in
the recordset implied by the form's RowSource property (or whatever it's
called - I don't have Access here to check). By "binding controls to
fields", in this context, I assume tat we both mean, "establishing a link
between the controls & the fields such that any changes to the control
values will be *automatically* updated into the relevant fields".

So to do an unbound form, you must trap every relevant event that can occur
in the form and the form'ds controls, & write code to update the database
accordingly. For example, if the user clicks your [Save] button, you would
need to write code to explicitly update the values in the existing record
(or create a new one). In an unbound form, Access will not do that for you.
You will have to do it yourself.

Bound forms are way easier, because they do all of the updating for you. All
you have to add is custom validation etc.

Why do you need an unbound form?

HTH,
TC
 
Suppose a form is created with no underlying table or query to create a
recordset but one is created in an event procedure.

Procedure OpenRecordSetandFindRecord
Dim db as DATABASE
Dim qdf as QueryDef
Dim strSQL as String
Dim rs as Recordset

Set db=CurrentDb
strSQL = "SELECT
Code:
, [Title], [Section] From coe_COEBank _
WHERE coe_COEBank.[IID#] = " & Str(Me![cmbSearchCode])
Set qdf = db.CreateQueryDef("qryFindIndicator", strSQL)
Set rs = qdf.OpenRecordset

End Sub

A.  What is the syntax for binding controls on the form to this recordset?
Does the recordset stay open once the End Sub command is reached?

Suppose there are two text boxes named  txtBox1 and txtBox2 and the value of
the [Code] field should be displayed in txtBox1 and the value of the [Title]
field in txtBox2.

B.  What should the row source of txtBox1 be set to? This:

[Form]![FrmIndicatorList]![txtBox1].ControlSource = rs.[Title]

Or this:

[Form]![FrmIndicatorList]![txtBox1].ControlSource = [Title]

Or this:

[Form]![FrmIndicatorList]![txtBox1].ControlSource = "Title"

So far no success.

Thanks.

John Wirt
 
Why crete the reocrdset?

You can stuff the sql you have right into the forms reocrd source.

So:
Dim strSQL as String

strSQL = "SELECT
Code:
, [Title], [Section] From coe_COEBank _
WHERE coe_COEBank.[IID#] = " & Str(Me![cmbSearchCode])[/QUOTE]

me.RecordSouce = strSQL
 
Back
Top