Solved

Putting a calculated field on a form (easy)!

Posted on 2011-03-17
3
259 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 400 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 100 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

Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

Question has a verified solution.

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

In a multiple monitor setup, if you don't want to use AutoCenter to position your popup forms, you have a problem: where will they appear?  Sometimes you may have an additional problem: where the devil did they go?  If you last had a popup form open…
Overview: This article:       (a) explains one principle method to cross-reference invoice items in Quickbooks®       (b) explores the reasons one might need to cross-reference invoice items       (c) provides a sample process for creating a M…
What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA code.
In Microsoft Access, learn how to use Dlookup and other domain aggregate functions and one method of specifying a string value within a string. Specify the first argument, which is the expression to be returned: Specify the second argument, which …

932 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now