Passing TextBox value between two UserForms - vba

I have two user forms in Excel VBA. I enter a value in the TextBox at the first UserForm. How do I pass the value to the second UserForm to display same value in a TextBox too?

Assuming that your forms are named:
Userform1 for this first form
Userform2 for the second form
And assuming that you have two textboxes one in each form as follow:
TextBox1 for the first textbox located in your first form
TextBox2 for the second textbox located in the second form
You assign the value of the first TextBox1 to TextBox2 using Userform2.TextBox2.Text=Userform1.TextBox1.Text

You can declare a public variable:
i.e X. In user form 1 x=textbox1.value and in user form2 textbox2.value=X.

Related

How can I simulate a keyPress event on a combo box when I click a buton on the same form im MS Access

I'm creating a form in MS Access with 10 butons simulatin a numeric keypad (only the values 0..9).
I would like to change the value of a combobox control in a subform each time I click on one of these butons. The combo box control is named "projectID"
I tried this but it is not the same as pressing the same key on a keypad.
Private Sub Buton3_Click()
Call Me.frmServDedicacion_Subformulario.Form.projectID_KeyPress(51) 'Ansii code for 3
end sub
I put this procedure as keypress event in order to verifiy the combobox method is executed, and it does (msgbox is ok) but the combobox doesn't receive the KeyAscii value.
Public Sub projectID_KeyPress(KeyAscii As Integer)
MsgBox Chr(KeyAscii)
End Sub
This looks like a problem referring to a control on a sub form from the main form. I still have trouble getting this right so I use a cheat sheet:
http://access.mvps.org/access/forms/frm0031.htm
I created a main form called main and put 10 buttons named button0 - button9 on the form and I dragged a form called mysubform onto the main form to create a subform. mysubform has a textbox named projectID. Then just set the click event to button0 to:
Private Sub button0_Click()
Me!mysubform.Form!projectID = 0
End Sub
Don't forget similar click events for buttons 1-9
some things that may be helpful:
! is the bang operator see:
Bang Notation and Dot Notation in VBA and MS-Access
by default, when you drag a form to create a subform control on another form, access gives the subform control the same name as the dragged form. so here mysubform refers to the subform control and not the original form used to make the subform.
Then .Form gets the form wrapped by the subform control.
I hope this answers your question

Setting ComboBox RowSource property to query in "GotFocus()" method leaves blank values in ComboBox Access VBA

I want to populate my ComboBox in an Access form using VBA based on data from another table. Previously to do this I did the following:
In the Property Sheet -> Data tab I filled out Row Source and Row Source Type fields with this information:
Now whenever I clicked on the dropdown for my combobox, it would populate the dropdown list with all of the names from t_people table.
This limited me however to when data changed in the t_people's name column. In order to get an updated list, I must close the form and re-open it so that the query runs again. I have limited the access to this Access file so that the user is only presented with x number of forms, and cannot close/open them or others.
My solution is to remove the query on the form load, and instead run the query every time the combobox gains focus, has a click event or something of the same sorts. I did this with the following event in VBA:
'Run when the "name" combobox gains focus
Private Sub nameCb_GotFocus()
[nameCb].RowSource = "SELECT name FROM t_people"
End Sub
I have set breakpoints and this code does run. However, the the combobox is not populated after it does. How can I get the combobox to populate with the values from a query for each time the combobox gains focus?
Set the RowSource in design and add a .Requery when entering the control.
Private Sub nameCb_Enter()
nameCb.Requery
End Sub

Populate textbox data to other forms' textbox

I have a ‘Login’ Form that opens when accessing database. It includes a textbox 'txtLoginID' bound to LoginID field in Employee table which has another field name called Fullname. On clicking OK button, a main form is opened. So far it’s OK.
I am trying to populate the textbox data to other form or subform's textbox to show the Fullname of the employee. I’ve put that other form textbox
controlsource=ReturnUser() ReturnUser is is public Function that is coded like that:
Public Function ReturnUser() As String
ReturnUser = DLookup("Fullname", "Employees", "loginID=" & Forms!Login!txtLoginID)
End Function
Still can’t get txtLoginId populated to other form’s textbox. I appreciate help
a textbox 'txtLoginID' bound to LoginID field in Employee table
That won't work. Make the textbox unbound and call your function in the AfterUpdate event of the textbox.

SSRS make Textbox Dropdown list

I am new to SSRS and I was wondering if I can make a textbox populated with a drop down list based on values that are not present in another textbox
For example: in textbox1 I have the value 1, and I want 2,3,4 to show up in textbox2 as dropdown list.
Is there such away to do that in SSRS?
I want textbox2 to be dropdown list that has all the items that has not been showing in textbox1. Textbox1 one is being populated based on the user input in the parameter. So it he user choose 2 the value in textbox1 should be 2 and the dropdown list (which I am calling it textbox2 here) show 1,3,4 only without 2

VBA Make a text box in a UserForm Active when the UserForm activates?

How can I make a text box in a UserForm activate when the UserForm activates, so that the user can start typing without having to click in the text box?
What you are looking for is the TabIndex Property.
Every object on your userform has one, it is the order to which object on the userform are selected when you press the tab button. The object with 0 TabIndex will be the active object when a form is loaded also:
So with the textbox selected go to the properties pane and look for Tabindex set this to 0 and your textbox will be selected on open.
You can also set other textboxes index to 1,2,3 and on, so that if the form is being filled out you can simply press tab to go from one text box to another.
Use .SetFocus. If your textbox's name is TextBox1, the following works:
Private Sub UserForm_Initialize()
TextBox1.SetFocus
End Sub
Let us know if this helps.