2

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?

0

2 Answers 2

5

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.

1
  • Thanks. Nice Answer. Should also note that I did have to use .caption for it to display.
    – talbright
    Jul 17, 2012 at 15:24
4

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.