user3791372
user3791372

Reputation: 4695

Access - Should I set the form controls or the underlying recordset?

I have a button on a form which pulls data from another database, and sets it to the current record in the current database.

When setting the data, should I be setting the controls on the form, or the underlying recordset? Is one preferable over the other, are there gotcha's that I'm overlooking. The only difference I can think of is that for the former, all the fields you want to set must have controls and requires much less code, whereas in the latter the controls don't need to exist.

e.g.

' setting controls directly - this appears to be fine as long as the 
' controls for the fields I want to set exist
Me!title = rs!title
Me!description = rs!description

' setting underlying recordset directly
dim rs2 as Recordset
set rs2 = Me.Form.Recordset
rs2.Edit
rs2!title = rs!title
rs2!description = rs!description  

Upvotes: 0

Views: 44

Answers (1)

asdev
asdev

Reputation: 943

Basically, it is a question of preference and the use-case; so there is no "correct answer".

I would use the case set data to Controls when I want to show the data to the user. Additionally it provides the opportunity to cancel the input by an undo-command e.g. when the user clicks a Cancel button.

If the data is not shown to the user while the data transfer, I would prefer setting it to the recordset directly.

Upvotes: 1

Related Questions