Entering data in a text box.

User avatar
HansV
Administrator
Posts: 78473
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Entering data in a text box.

Post by HansV »

You have two options:

1) Declare shared variables at the top of the module, above all procedures (Subs) and functions.

If you use

Code: Select all

Dim dblProfit As Double
you can use the variable dblProfit in all procedures and functions in the same module. If you want to be able to use it in all modules in the database, use the keyword Public:

Code: Select all

Public dblProfit As Double
2) Alternatively, you can pass variables as arguments to other procedures and functions:

Code: Select all

Sub Test()
    Dim dblProfit As Double
    dblProfit = 37.11
    Call DoubleProfit(dblProfit)
End Sub

Sub DoubleProfit(SomeValue As Double)
    MsgBox 2 * SomeValue
End Sub
When you run Test, you'll see

S2158.png
You do not have the required permissions to view the files attached to this post.
Best wishes,
Hans

bknight
BronzeLounger
Posts: 1387
Joined: 08 Jul 2016, 18:53

Re: Entering data in a text box.

Post by bknight »

Weel everything will be in the same module, so my initial Dim statement will work.
If I program a message box the has more than one line of information, how are the additional lines seperated? I tried ; and , finally : all fail with expected list separator(s).

User avatar
HansV
Administrator
Posts: 78473
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Entering data in a text box.

Post by HansV »

For a message box, you have to concatenate with vbNewLine:

MsgBox "This is line #1" & vbNewLine & "This is line #2"
Best wishes,
Hans

bknight
BronzeLounger
Posts: 1387
Joined: 08 Jul 2016, 18:53

Re: Entering data in a text box.

Post by bknight »

What is produced is a one long string of everything.

Desired
comment 1
comment 2
comment 3
comment n
I would assume that 255 is the max lnes or charcters.

ETA: Is there a message that is persistent, but will allow the keyboard to function on "what is underneath"?

User avatar
HansV
Administrator
Posts: 78473
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Entering data in a text box.

Post by HansV »

The maximum length of the string displayed by MsgBox is 1023 characters.
Remark: this includes line breaks; each vbNewLine counts as 2 characters (carriage return and line feed).
Best wishes,
Hans

User avatar
HansV
Administrator
Posts: 78473
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Entering data in a text box.

Post by HansV »

MsgBox is "modal", i.e. you cannot do anything with the application while it is displayed.
In Access, you can create a popup form to display a message; in Excel, you can create a userform and set its ShowModal property to False for this purpose.
Best wishes,
Hans

bknight
BronzeLounger
Posts: 1387
Joined: 08 Jul 2016, 18:53

Re: Entering data in a text box.

Post by bknight »

message 1 & vbNewLine & message 2 etc? Where is the create popup forrrm in 2007?

User avatar
HansV
Administrator
Posts: 78473
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Entering data in a text box.

Post by HansV »

Literal text string have to be enclosed in quote:

MsgBox "message 1" & vbNewLine & "message 2"

You can turn any form that you create in Access into a popup form: on the Other tab of the Property Sheet, set the Popup property of the form to Yes.
Warning: do not set the Modal property to Yes, for that would make the form behave like MsgBox: you cannot interact with the rest of the database while a modal form is open.

S2164.png
You do not have the required permissions to view the files attached to this post.
Best wishes,
Hans

bknight
BronzeLounger
Posts: 1387
Joined: 08 Jul 2016, 18:53

Re: Entering data in a text box.

Post by bknight »

I see it under "Other" on mine, yes I understood the quotation marks, but didn't type them in, sorry.

bknight
BronzeLounger
Posts: 1387
Joined: 08 Jul 2016, 18:53

Re: Entering data in a text box.

Post by bknight »

What I get is gigantic, compared to what I want. I would like say a3x3 box, but it default to ~5.625
"46-Buy to Open" & vbNewLine & " 47-Buy to Close" & vbNewLine &"48 Sell to Open"& vbNewLine &"Sell to Close"
results in "46-Buy to Open" & vbNewLine & " 47-Buy to Close" & vbNewLine &"48 Sell to Open"& vbNewLine &"Sell to Close"

I guess I don't understand the useage of vbNewLine.
You do not have the required permissions to view the files attached to this post.

User avatar
HansV
Administrator
Posts: 78473
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Entering data in a text box.

Post by HansV »

What exactly have you done to create this?
It might help if you attached a zipped copy of the database.
Best wishes,
Hans

bknight
BronzeLounger
Posts: 1387
Joined: 08 Jul 2016, 18:53

Re: Entering data in a text box.

Post by bknight »

Too big, I believe,
To create I went to create forms and selected popup yes modal no
Typed in messages as you had suggested I do.

User avatar
HansV
Administrator
Posts: 78473
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Entering data in a text box.

Post by HansV »

Where did you type the message?
Best wishes,
Hans

bknight
BronzeLounger
Posts: 1387
Joined: 08 Jul 2016, 18:53

Re: Entering data in a text box.

Post by bknight »

Inside a label box on the grid of the default detail that pop upped once I selected popup to yes, modal to no.

ETA: I was in form design.

User avatar
HansV
Administrator
Posts: 78473
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Entering data in a text box.

Post by HansV »

You cannot type an expression (formula) directly into the Caption property of a label control.

Option 1: set the Caption property using VBA in the On Load event of the form:

Code: Select all

Private Sub Form_Load()
    Me.LabelName.Caption = "text 1" & vbNewLine & "text 2" & ...
End Sub
Option 2: use a text box instead of the label. Set the Control Source of the text box to

="text 1" & vbNewLine & "text 2" & ...

(You may want to set the Enabled property of the text box to No and its Locked property to Yes)
Best wishes,
Hans

bknight
BronzeLounger
Posts: 1387
Joined: 08 Jul 2016, 18:53

Re: Entering data in a text box.

Post by bknight »

Ok, didn't know that the control wouldn't accept a concatenated formula.

bknight
BronzeLounger
Posts: 1387
Joined: 08 Jul 2016, 18:53

Re: Entering data in a text box.

Post by bknight »

I was editing a record to test my code and I changed the quantity for one of the records. then just tabbed through price, commission and fees. I noted that nothing changed. I have code in almost all fields After_Update events. Some of the fields are dependent on quantity. I know now that any code on an after_Update wont changed until the data has changed.Is there a good ways to change the data in the dependent fields, or just change then also?

User avatar
HansV
Administrator
Posts: 78473
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Entering data in a text box.

Post by HansV »

In most situations, it makes no sense to change the value of other controls (fields) while you are still editing a control (field).
If you really need to, you can use the On Change event of the control. But I'd use that sparingly.
Best wishes,
Hans

bknight
BronzeLounger
Posts: 1387
Joined: 08 Jul 2016, 18:53

Re: Entering data in a text box.

Post by bknight »

Ok I'll change all the ones affected manually.

bknight
BronzeLounger
Posts: 1387
Joined: 08 Jul 2016, 18:53

Re: Entering data in a text box.

Post by bknight »

I have a date/time field and I wish to group by dates, but that will only work if the dates are days. How is it possible in a query to "reduce" a date/time to just a Date?