?
Solved

Putting a calculated field on a form (easy)!

Posted on 2011-03-17
3
Medium Priority
?
270 Views
Last Modified: 2012-05-11
Hi see attached.

I have a very simple form based on a very simple table.
If the [Price] field is > 100 then I want to display the wording "High"

See code below where PriceType is determined to be "high" or "low" .

How do I get the "PriceType" displayed on the actual form.  See my attempt gives an error.
Private Sub Form_Current()
Dim PriceType As String
If Me.price > 100 Then PriceType = "High" Else PriceType = "Low"
End Sub

Open in new window

Database8.zip
0
Comment
Question by:Patrick O'Dea
3 Comments
 
LVL 77

Accepted Solution

by:
peter57r earned 1600 total points
ID: 35157521
Add a textbox to the form.
If the name of the textbox is txtPriceType then you add another line

If Me.price > 100 Then PriceType = "High" Else PriceType = "Low"
me.txtPricetype = pricetype

You could do without the variable completely and just set the textbox directly in the 'if' statement.
0
 
LVL 10

Assisted Solution

by:t_hungate
t_hungate earned 400 total points
ID: 35160886
You can also do this by adding two hidden textboxes one for high and one for low, then use your if statement to change the visible property of the textbox.

If Me.txtPrice > 100 then
    Me.txtPriceTypeHigh.visible = true
    Me.txtPriceTypeLow.visible = false
else
    Me.txtPriceTypeHigh.visible = false
    Me.txtPriceTypeLow.visible = true
End if
0
 

Author Closing Comment

by:Patrick O'Dea
ID: 35161185
thanks again
0

Featured Post

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Windows Explorer lets you open cabinet (cab) files like any other folder. In VBA you can easily handle normal files and folders, but opening and indeed creating cabinet files takes a lot more - and that's you'll find here.
In a use case, a user needs to close an opened report by simply pressing the Escape (Esc) key. This can be done by adding macro code in Report_KeyPress or Report_KeyDown event.
Using Microsoft Access, learn some simple rules for how to construct tables in a relational database. Split up all multi-value fields into single values: Split up fields that belong to other things into separate tables: Make sure that all record…
In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.
Suggested Courses

840 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question