473,396 Members | 1,738 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

How do I alter a global constant from an unbound txtbox on a form?

I have a number of global constants in a module made for that purpose. They are primarily price constant that rarely change, but also includes VAT and discount rates.

How can I alter these values from a form?


I have a form with the values showing in textboxes, but they are not editable.

Am i going about this the right way?

Thanks (again) for any help you can give.

RPE
Feb 18 '11 #1

✓ answered by colintis

Well I don't want to have good weather in this season down in Australia as its too hot here....Besides since the bloody flood passed by last month, most places are still maintaining power by renting generators, I wish I'm replying you in a swimming pool...

Back to topic, indeed a constant is not editable, sorry that I missed out this part. If possible, try search the constant variable where its created, it must be within the modules or classes. Or it can be a datatype function that generates with certain methods.

7 1991
colintis
255 100+
Have you tried making a command button to save the new values?

As the textboxes simply read once from the global variables, then it could be re-assign with new values by executing an event such as command button's On_Click()
Feb 18 '11 #2
Thanks for the reply colintis:

I'd been working flat out on a complicated (for me!) database for hours when I came across this problem. I see what you mean about the cmdButton, but I also can't actually alter the value in the textbox - the same as if it were locked. I'm guessing it's something to do with the 'variables' being global and/or in a separate module, but I can find nothing on this in any of my books or online.

The 'VAT issue' (sales tax in most countries I think) must be a common one, but having already tried to put such values into a table, I figured the best way would be a constant...but how does one alter a constant...by definition I guess you don't...maybe a 'normal' variable?
Thinking while typing! Bet you got better weather outside your window than I have!!
Thanks again.
stonward.
Feb 18 '11 #3
colintis
255 100+
Well I don't want to have good weather in this season down in Australia as its too hot here....Besides since the bloody flood passed by last month, most places are still maintaining power by renting generators, I wish I'm replying you in a swimming pool...

Back to topic, indeed a constant is not editable, sorry that I missed out this part. If possible, try search the constant variable where its created, it must be within the modules or classes. Or it can be a datatype function that generates with certain methods.
Feb 18 '11 #4
I hope the flood literally 'passed you by'....

I've been going about this 'constant' problem the wrong way of course...I'm gonna re-ask the question from where I am now: I've placed a public variable in a 'declarations' module, initialized it with a value and used a function to call it on my form. Works great, but still can't figure how to alter the value!
Thanks for your time thus far Colintis.

stonwardR
Feb 19 '11 #5
NeoPa
32,556 Expert Mod 16PB
It's good sense to post the new question separately (found From a txtbox on a form, how can I alter an initialized variable value?). I read it but couldn't see any way it could make sense. Maybe that's because I don't make the sort of assumptions you would Royston. Maybe Colintis would fare better. I'm happy to look again though if it can be made clearer.
Feb 19 '11 #6
ADezii
8,834 Expert 8TB
@ALL - You can actually modify the Value of a CONSTANT Permanently from within a Form. You would Open the Code Module containing the CONSTANT Declaration, Search for the Current Value assigned to the CONSTANT, change it, Close and Save the Module, then return Focus to the Form where the Code originated.
Feb 19 '11 #7
Lysander
344 Expert 100+
As ADezii says, this can be done in code. I do it all the time when changing assigned drives.

Obviously you would need to adapt the text below to match your own constant string, but this is the code I use.
Expand|Select|Wrap|Line Numbers
  1. Private Sub cmdChangeDrive_Click()
  2. On Error GoTo cmdChangeDrive_Click_Err
  3. Dim db As Database
  4. Dim td As TableDef
  5. Dim i As Integer, j As Integer, var As Variant
  6. Dim GotPrimary As Boolean
  7. Dim strAttach As String
  8. Dim strNewAttach As String
  9. Dim strNewCode As String
  10. Dim strNewMDW As String
  11.  
  12. Dim mdl As Module
  13. Dim intLine As Integer, strLine As String
  14.  
  15. '"c:\Education\EducationCode.mdb"
  16. strNewCode = NewLiveCode & Right(LCode, Len(LCode) - 1)
  17.  
  18. '";DATABASE=c:\Education\EducationData.mdb"
  19. strNewAttach = Left(LData, 10) & NewLiveData & Right(LIVEDATA, Len(LIVEDATA) - 11)
  20.  
  21. '"c:\Education\Education.mdw"
  22. strNewMDW = NewLiveMDW & Right(LMDW, Len(LMDW) - 1)
  23.  
  24.         DoCmd.OpenModule "basConstants"
  25.         ' Return reference to Module object.
  26.         Set mdl = Modules("basConstants")
  27.  
  28.         For intLine = 1 To mdl.CountOfDeclarationLines
  29.         strLine = mdl.Lines(intLine, 1)
  30.         If InStr(strLine, "LIVECODE") > 0 Then
  31.             mdl.ReplaceLine intLine, "Global Const LIVECODE = " & Chr(34) & strNewCode & Chr(34)
  32.         End If
  33.         If InStr(strLine, "LIVEDATA") > 0 Then
  34.             mdl.ReplaceLine intLine, "Global Const LIVEDATA = " & Chr(34) & strNewAttach & Chr(34)
  35.         End If
  36.         If InStr(strLine, "LIVEMDW") > 0 Then
  37.             mdl.ReplaceLine intLine, "Global Const LIVEMDW = " & Chr(34) & strNewMDW & Chr(34)
  38.         End If
  39.         Next
  40.         DoCmd.Close acModule, "basConstants", acSaveYes
  41.  
  42. cmdChangeDrive_Click_Exit:
  43.    Exit Sub
  44. cmdChangeDrive_Click_Err:
  45.    MsgBox Err.Description & " in cmdChangeDrive_Click"
  46.    Resume cmdChangeDrive_Click_Exit
  47. End Sub
  48.  
Feb 20 '11 #8

Sign in to post your reply or Sign up for a free account.

Similar topics

9
by: Krisztian Kepes | last post by:
Hi ! I want to create an module and I want to use some Global Constant in it. How to I create an global constant in module what is accessable in from other modules ? like this example: ***...
2
by: Matt Smolic | last post by:
02.06.04 I need some help displaying a public variable on a form. The variable is declared and initilazied in a module at startup (and declared Public). I have verified this with a...
2
by: Lupina | last post by:
How to do global pointer , which indicates on the second form ? If I want e.g. invoke another form I do it like this : private: System::Void menuItemDlg_Click(System::Object * sender,...
6
by: Anton | last post by:
Hi folks, Is there any way to retrieve a global declared constant from another database. I want to use it for version tracking purposes. The constant that I am after is and will remain in a static...
2
by: tkhouk | last post by:
I have a small form with two unbound look-up fields (one for an ID and one for last name). Each unbound field has a command button that actually goes to my table and brings in the records. How can...
1
by: SpreadTooThin | last post by:
How do I define a constant that I can use in my script... For example lets say I have a file called constants.py and in there I have PI = 3.14 in my test script I do: from constants import *...
5
by: luanhoxung | last post by:
hi all!! i face to a new trouble. in my form, i have a textbox(unbound) that informs details of product when i choose the value of combo box(IDPro). it is ok when i choose the first value of...
31
by: DWolff | last post by:
I'm somewhat new to Access, and have no VB experience at all (except for modifying existing code where obvious). I built a data entry form that works fine. Typically, a client will call in and...
5
by: tech.rawsteak | last post by:
I have a function that retrieves a user's login name from their workstation and looks it up on an employee table to return their full name (ie: jsmith -John Smith). Their full name is then...
5
by: hbaf208 | last post by:
I have a combobox on a subform that is based on an SQL that uses a listbox on the unbound parent form as the criteria. When the form is first loaded, it works perfectly, limiting the dropdowns to...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.