473,226 Members | 1,405 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,226 software developers and data experts.

How can I set up a command button to ask for input to change the default value of a text box in an Access form?

What I am trying to do is to change the default value using a command button. We have over 200 work centers and I want to be able to change it on the fly (so to speak). Here are the 2 lines of code that I have been trying to get one of them to work:

Forms!frmMainentry!txtStation.DefaultValue = """?"""

Me.txtStation.DefaultValue = InputBox [What Workcenter Do You Want To Change Too?]

The first one works, but to change the value, I have to change it in the code.
The second one give me an error:

Compile error: Expected end of statement.

I've been working on this with researching the internet, my Access Bible just trying different things for 5 days.
It will be on a computer at work, but both mine and at work are running Windows 10, at home I am using Access Pro 2010 at work we are using Access 2016.
If you need more info, let me know and I will give what I have and will be checking here daily.
Any help you can give would be GREATLY appreciated.
Jun 5 '21 #1
1 2547
32,554 Expert Mod 16PB
DefaultValue properties can be awkward. Generally speaking it has to be a string value that evaluates to an assignment. So, assuming a Workcentre (Feel free to change spelling if an American cousin ;-) ) has something like a three-character code (EG. CRO or BRI.) then an assignment in code could be something like :
Expand|Select|Wrap|Line Numbers
  1. Me.txtStation = "CRO"
Note the quotes. In that case the DefaultValue value would have to include the quotes too :
Expand|Select|Wrap|Line Numbers
  1. Me.txtStation.DefaultValue = "CRO"   ?
No. That is simply the string itself. The quotes are interpreted by VBA to enable it to recognise the string as a string. The resultant string is simply CRO. Not good enough. Works OK with a number but not with strings.

What you need there, bearing in mind that quotes within a string need to be doubled up in order to be recognised as quotes within the string rather than the end of the string, is :
Expand|Select|Wrap|Line Numbers
  1. Me.txtStation.DefaultValue = """CRO"""
Here's how VBA interprets each quote :
"#1 Start of a string.
"#2 End of string or start of a pair?
"#3 #2 was clearly one of a pair so insert a single double-quote in next position of string.
"#4 End of string or start of a pair?
"#5 #4 was clearly one of a pair so insert a single double-quote in next position of string.
"#6 End of string or start of a pair?
End of string.
That leaves you with a string of "CRO", which should work.

All well & good, but how to code that?
Expand|Select|Wrap|Line Numbers
  1. Private Sub cmdFixWC()
  2.     Dim strWork As String
  4.     strWork = InputBox("Which Workcentre do you want to Change To?")
  5.     Me.txtStation.DefaultValue = Replace("""%WC""", "%WC", strWork)
  6. End Sub
Jun 5 '21 #2

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

Similar topics

by: Ragnar Heil | last post by:
I have got a form where I offer a default date (01.01.2004) and visitors can change it and make queries in the database. After changing this, the customized date should be displayed in the form...
by: Will | last post by:
I am upsizing an access application to vb.net. In access textbox, combos and checkboxes can have default values, which are assigned in the properties for the control. How can I set a control's...
by: emandel | last post by:
I am an armature access programmer trying my best to design my own database so your patience and detailed instructions is much appreciated. Here is my question: How do I get a command button (on...
by: mdpems | last post by:
The organization I work for needs to use a form that we can send to a billing department that shows supplies we used and Mission#'s. I have a form to select supplies used and total the costs of...
by: sourabhmca | last post by:
Hi friends, I have a table : create table abc (a int,b smalldatetime default getdate()) then insert value like insert into abc(a) values(1) now I want to change default value of column b be...
by: sillyr | last post by:
Hi- I'm using Access 2007. I wanted to change a default value for a field that previously had no default value. I though it would be easy- just set the default value setting to the number t hat I...
by: DanicaDear | last post by:
I will search for on frmCustomers. When I find the customer, I click a button btnShowOrders and it opens frmOrders with subfrmOrderDetails2. (I'm having trouble grasping the previous sentence...
by: RGM2244 | last post by:
I appreciate the help in advance, I have a Microsoft Access form that users enter information into (text boxes and option buttons) and on that form I have a button that users are able click. Here...
by: mshakeelattari | last post by:
Is there a way to add a custom command button in the default shortcut/right-click popup menu in ms access 2016 or to create a custom popup menu with all the commands of the default popup menu along...
by: jemy | last post by:
I have a built a database for backflow testing. The database contains 3 tables: Client Information, Testing Date and hyperlinks to actual document and Invoice information. I have built the...
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
by: fareedcanada | last post by:
Hello I am trying to split number on their count. suppose i have 121314151617 (12cnt) then number should be split like 12,13,14,15,16,17 and if 11314151617 (11cnt) then should be split like...
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...

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.