How do I get the value of a textbox in Word?
I know in excel this is the right syntax: ActiveSheet.Shapes(x).Name.
I thought in word this would be the right syntax
ActiveDocument.Shapes(x).Name,
but this doesn't seems to work.
With this piece of code I also couldn't find a textbox:
For i = 1 To ActiveDocument.Shapes.Count
MsgBox ActiveDocument.Shapes(i).Name
Next i
To get the value of a standard textbox, use this:
ActiveDocument.Shapes(1).TextFrame.TextRange.Text
To get the value of ActiveX controls (OLEobjects), use this syntax where TextBox1 is the control name, use
ActiveDocument.TextBox1.Value
To get the name of ActiveX controls, use this:
ActiveDocument.InlineShapes(1).OLEFormat.Object.Name
I used tags (object properties -> assign a tag name) to edit the object's value. Use this syntax to change the value of a content control:
ActiveDocument.SelectContentControlsByTag("Your-Content-Control-Tag").Item(1).Range.Text = "your-preferred-value"
Anyway, thanks Rachel Hettinger for your patience ;).
Related
want to enter a text into texbox where the tag is input tag, it has ID as well
i am using ie.document.getElementsById("myId").Value = "newtext"
however its giving an error "object doesn't support this property or method"
please give resolution
You can't do it like this. The best way to set the value is to add the attribute "value" to the element:
Example:
ie.document.getElementsById("myId").setAttribute("value", "newtext");
That should work.
In my Access database, I have tables with the naming convention of "t_customers" or "t_orders". I have a combo box which lets me pick from these options. For a better look, I want to have the options in the combo box without the "t_", so one of the options is just "customers". Then in VBA, I can access the combo box's value of "customers" and then pass that as a parameter to my function which will export the contents of the associated table "t_customers" to an excel file.
Is this possible to do? I can think of using a select case statement and for each combo box value I manually assign the related table value, but there has to be a better way. Is there some sort of short cut that does this in Access using a relationship or similar feature without coding? Or is there a simpler way to code this?
EDIT:
I am also trying to get the value of the current item selected in my combo box named "cbTable". I have no macros attached to the combo box. I have a button that when pressed it runs a macro which calls my VBA function. In the function I have this code:
Dim cbValue As String
cbValue = cbTable.Value
MsgBox (cbValue)
I get this error:
Runtime Error '424'
Object Required
The error is on the
cbValue = cbTable.Value
line. What is wrong with this code and how do I get the current value of the combo box?
Thanks in advance.
You can set your RowSource for your combobox to
SELECT MSysObjects.Name, Replace(MSysObjects.Name,"t_","") AS Expr1
FROM MSysObjects
WHERE (((MSysObjects.Type)=1) AND ((MSysObjects.Flags)=0));
Then set the Column Count to 2, the Column Widths to 0;2 (the second number just needs to be any positive number) an the Bound Column to 1.
Now when you go to call your function the value of the combobox will be the real name of the table, t-customers, but what you saw on your form was customers.
As for accessing that combobox a few things need to be in place.
Let's say you have a form, Form1, and your combobox, cbTable, is on that form.
So when your form runs it looks like this
Now let's say you have an OnChange even for that combobox
Notice that when you type cbTable it appears in the intellisense (ctrl+space). This tells you that your object is accessible at this scope.
Now if you were in another module where that variable is out of scope you would get this error when you try to compile.
Because Module1 has no idea what cbTable is. However, you can reference anything so long as it's fully qualified. So if we run this test with your form open, and "orders" selected all 3 of these lines are equivalent
Forms("Form1").cbTable
Form_Form1!cbTable
Forms("Form1").Controls("cbTable")
Notice at the top of all my modules it says Option Explicit. This forces your code to basically be checked for syntax/scope validity before you run it. Tools > Options
I currently have a form. The form contains a subform that displays a Query. The Form also has 2 Text Boxes and buttons for both Boxes. The first box acts as a filter for the query to filter specific record. The second box is intended to be used to hide columns in the query. My issue is that my code will not recognize the text box, or any outside source from my form as a Field Name to be found. Here is my current code:
Private Sub Command137_Click()
Forms![Vermont]![Query1 subform].Form.[Query1 Field Name].ColumnHidden = True
End Sub
Currently if I replace "Query1 Field Name" with any field name that exists in the query the column will hide. However if replaced with anything else I recieve the following error:
"Runtime Error '2465'
Microsoft Access Can't Find the Field '|' reffered to in your expression"
I am pretty sure that I am not referencing the Form Control correctly. I have tried replacing [Query1 Field Name] with the following:
[Text142.Text]
[=Text142]
[Text142]
[Forms![Vermont]![Text142]]
I am very new to VBA but I definitely feel as if this is an easy fix; if possible.
Thank you in advance for any help!
Subform references are always a bit weird. This should work, though:
Forms![Vermont]![Query1 subform]![Text142].ColumnHidden = True
I created a form in MS Access 2010 and added a textbox here. Then I created a simple query (for example SELECT 10 AS studval;) and tried to set in Properties (of textbox) -> Data -> Control Source this query, but I got error #Name?.
How do I fix this error?
All names of query, textbox, query return values are correct. Or maybe are there any other ways to bound textbox and custom SQL query?
There is no easy way to do it, but it is possible using the form's On Activate event. First set up a query (Query1) with a single value called "studval" then open the form properties and add an Event Procedure for On Activate. It should look like this:
Private Sub Form_Activate()
Dim myString As String
myString = CurrentDb.QueryDefs("Query1").OpenRecordset.Fields("studval")
Me.Text0.SetFocus
[Text0].Text = myString
End Sub
You need to set the Control Source of the form to the query rather than the control source of the text box. A text box control source can only refer back to it's form's control source.
If you want just one text box bound to a query you have to create a subform linked to the parent form with that text box in it.
I have a combobox in Excel created as the picture suggests, and it has a range associated to it.
How can I give it a default value from this range, through VBA?
ActiveSheet.Shapes("DropDown1").ControlFormat.Value = "Germany"
I tried the above code, but it doesn't work. I believe the syntax is not correct. Can you please help?
Thank you!
You can use the DropDown type, it doesn't show up in the intellisence when you type.
Dim DropDown1 As DropDown
Set DropDown1 = ActiveSheet.DropDowns("DropDown1")
DropDown1.Value = 1
The value is the index of the dropdown, so 1 is the first in the list etc. Use 0 to have no value selected. Also make sure the name "DropDown1" is the correct name for the control, if you right click the control in the excel sheet you'll see the name for the control to the left of the function bar.