Set focus on ComboBox (ActiveX Control) after code execution - vba

I have an Excel file with a combobox (name = "Combobox1"). After running a script (basically pasting the selected value in "the next row" of a column) I want the focus to be reset on the combobox at the end of the script, so doing allowing me to type the next entry in the Combobox without having to click on the ComboBox text field first.
This does the job in Excel 2013 but I would like to have it working in 2007 as well:
Combobox1.Activate
Anyone any idea?
Or:
I can replace the combobox with an in-cell dropdown list (data validation) and the same data validation as the one I have in the combobox at the moment, but then I have another issue:
For a ComboBox you can choose to have the dropdown list active, but for an in-cell data validation that is not the case, at least not if you want to be able to type in the cell after the list is shown with ALT+UP or
Application.SendKeys "%{UP}"
Any idea here?

If this combobox is on a worksheet and not a userform, then "Combobox1.select" should return the focus to the combobox.

Related

word vba combo box values not displaying although populated

I am trying to populate Mail Merge Data fields from excel database and I am successful in pulling it, but when trying to add it in user form combo box, it is not displayed. Although combo box is populated with 3 blank rows. Screenshot attached.
Below code is written in Module1. Do I need to write anything in Combobox1_change() in userform as well?
For Each aField In ActiveDocument.MailMerge.DataSource.FieldNames
UserForm1.ComboBox1.AddItem
Next aField
Userform screenshot
You haven't told the userform what to add to the combobox. For example:
For Each afield In ActiveDocument.MailMerge.DataSource.FieldNames
UserForm1.ComboBox1.AddItem afield.Name
Next afield

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

Excel function Implemented on Access

I am working on a "inventory check" Excel worksheet that finds the item code and then inserts a timedate in a the date column.
Table has two Columns; 'Item Code' and 'Date'
I have made a macro on Excel that basically asks for item code, and inserts the date in the corresponding cell.
I am trying to implement this in Access. Does anyone have any references?
Not sure which version of Access so I'll try to be generic:
In Access - find the table and create a form from it (Usually by clicking a button on the toolbar).
Switch to design view in the form, in the header add a combo box using the control wizard and ask it to "Find a record in my form based...." - set it to the field "Item Code"
Set the visible property of the item code box in the detail section to False
create a macro to set a property - control is "Date", property to set is "Value", value to set it to is "=Now()"
Save this macro
Add a command button, in the wizard set it to run your saved macro

vba can't type a simple function in textbox controlsource property

I'm new to VBA btw ..
I built a userform with multiple textboxes that return a value based on a combo box selection.
so in the textbox control source property, I can write formulas like "=index( match) and stuff
but can't write something like "=sheet1!b4+sheet1!c7"
and I get "Couldn't set the controlsource property, invalid property value" error
my formulas are more complicated than this of course, (and they work if I type them in a normal cell) .. but it seems that I can't write any calculation sign + - * / into the controlsource property
any idea why ????
That's because the cell is then "connected" to the text box. If you update the text box you are also updating the linked cell on sheet1. But if you are trying to link two cells with =sheet1!b4+sheet1!c7 and afterwards you are changing the value in the textbox then Excel wouldn't know which cell to update. Should only Sheet1B4 get updated or only Sheet1C7? Maybe both cells get 50% of the value?
In short: one text box can have only one control source and thereby link the text box to the referenced cell.

List or combobox to select entries as you type

In an excel spreadsheet (2013) I have a listbox which contains a list of about 50 items. Is it possible to when in the list box to type "M" and for it to jump to any entries with "M"?
I know this is possible using a userform and combo box by setting the MatchEntry to 0 - frmMatchEntryFirstLetter. Is it however possible to do this using a list or combobox embedded in an excel worksheet?
I don't know on what version of Excel you're on, but with an ActiveX combobox you can do the same as in a userform (set the MatchEntry).
Works for me in several projects.