talbright
talbright

Reputation: 446

Create "Winform" in MS Access

Is it possible to create a form in MS Access 2007 that is not dependent on a recordset? I want to create a form that would just handle simple calculations, but would not rely on any data from the database.

This is the code I've tried to use, but when I run it I get a compile error "Method or data member not found."

Private Sub btnCalc_Click()
Dim TotalCost As Integer
Dim DisposalCost As Integer
Dim CostRatio As Integer
TotalCost = txtTotalCost.Text
DisposalCost = txtDisposalCost.Text
CostRatio = TotalCost / DisposalCost
lblCostRatio.Text = CostRatio
End Sub

Is there something wrong with my code, or do I need to just create a winform to handle this?

Upvotes: 2

Views: 236

Answers (2)

Fionnuala
Fionnuala

Reputation: 91356

Yes, it is perfectly possible. Do not refer to the .text property, the text property is only available when a control has focus. if you must use a property - it is not required - use .value.

For labels, you do indeed need the .caption property.

There are advantages in using a textbox for the answer, because you can set it to a function or a calculation. For example, you can set the control source to:

= txtText1 / txtText2

You can prevent the results textbox from being edited with the locked and / or enabled properties. To ensure that the calculations is performed, you will need to set the format property to a number or currency format.

Upvotes: 5

HansUp
HansUp

Reputation: 97101

If lblCostRatio is a label control, your error message is due to this line:

lblCostRatio.Text = CostRatio

A label control does not have a .Text property. Look at altering its .Caption property instead.

Upvotes: 4

Related Questions