Excel Form VBA Combobox reset - forms

This should be easy but I can't seem to find anything to solve. I have a Form in Excel using VBA. The Excel sheet has four columns populated with data and the Form displays those fields.
The user then selects a value in a combobox, uses a command button to submit the responses and the values from the combobox are written to the Excel sheet.
The user then uses a command button to advance one row down in the spreadsheet and load the four values from a new row. This all works great.
The issue I am trying to solve is that the combobox remains selected to the value in the prior selection. I'd like to reset the combobox so nothing is selected and the user has to make a selection again for the next row.
Below is the code I am using to load the combobox and to set a variable for what the user selected. Can't seem to get the combobox back to it's default state after the user has submitted the form.
Private Sub cbDesAccWanted_Change()
Select Case cbDesAccWanted.Text
Case "Yes"
desacc = "Yes"
Case "No"
desacc = "No"
End Select
cbDesAccWanted.Text = desacc
End Sub
Private Sub cbDesAccWanted_DropButtonClick()
cbDesAccWanted.List = Array("Yes", "No")
End Sub

There are two ways to reset the combobox. Take your pick:
1
cbDesAccWanted.Value = Null
2
cbDesAccWanted.ListIndex = -1

the line
cbDesAccWanted.Text = desacc
is totally unnecessary.
Using cbDesAccWanted_DropButtonClick is not the right place to populate the list of values. This list should be set up when the form is first shown to the user.
(unelss the values it shows chnages in which case change it when the row changes or something, not when the user clicks on it)
So when theuser clicks the down arrow to move to thenext record include the following line
Me.cbDesAccWanted.text = Me.cbDesAccWanted.List(1)
Note (1) access teh 2nd item in the list which is No.
So this reset it to the default value of No.
Ok.

Related

How to display sheet(s) on dashboard using navigation?

I'm creating a dashboard on Tableau and I want to have a set of navigation buttons that correspond with the sheets I've created. When a button is clicked I want the corresponding sheet to be displayed on my dashboard instead of navigating to the sheet itself. I want all of the sheets to be displayed in the same place on my dashboard. For example, If button 1 is clicked I want sheet 1 to be displayed on my dashboard. If button 2 is clicked I want sheet 2 to be displayed on the dashboard in the same place. I'm new to Tableau and would appreciate any help with this!
The easiest way to achieve this is using parameters.
As a first step you need to creat a parameter with a list of values matching the number of worksheet, like: Worksheet 1, Worksheet 2, etc...
Then you have to create N calculated fields in order to check if the "actual" worksheet is the one "selected in the parameter", using "ok" and "ko" as results for your filters, keeping just "ok".
The formula could be something like this (assuming you're doing the CF for the 1st worksheet, and the other ones differ just for the value):
if parameter = 'Worksheet 1' then 'ok' else 'ko' end
Doing so, all you're worksheets will present data just one at a time because all of them but the one matching the valus in parameter will be blank.
Then you can create your dashboard putting a vertical (horizontal as well if you like) container in it which will be the the "place" where you'll drag all your worksheets.
Be sure to NOT modify the spacing and height of them; just le tableau handle that for you, otherwise the trick won't work.
Once you're finished you will end up having a container with N worsheets in it, with just one of them dysplayed at once.
Once you'll become familiar with parametr actions, you will no longer need to have the parameter displayed on the dashboard (show parameter) because using a worksheet connected to the parameter values you will be able to decide the value of the parameter via click on your additional worksheet acting like a series of button (woeksheet 1, worksheet 2, etc...)

Excel stops working when adding new row to the Table

I don't know why but when I try to do this Excel Quits without saving anything:
On Sheet1 I have 11 Rows x 6 cols formatted as Table. With 1st row as Table Header.
I assign col A as a STU_ID Named Range using Name Manager.
I have only a listbox on the Userform. And I give RowSource property as =STU_ID . I get the col A data on the list box.
Now when I go to Sheet1 and try to add more data on next row of the table. Excel quits saying it has stopped working. Windows is checking for error and it restarts on a blank Workbook.
Shouldn't Listbox be dynamic and get data from Name Manager as I add them on the sheet ?
I am using MS Excel Pro 13 on Win 10 64 bit.
This is a bug in Excel. As a workaround, use the .List property instead of the .RowSource.
Try something like this in the UserForm's code:
Private Sub UserForm_Initialize()
ListBox1.List = Range("table1[abc]").Value
End Sub
This way it will be dynamic, and it will work.
If you need it to change while the userform is displayed, put a small code to the Sheet change event, that updates the list every time the sheet changes. (This is only necessary if your form is modal, and you want it to reflect the changes made in real-time.)

Access Form with checkbox toggled textboxes to make visible

Im trying to cut down on the clutter of my form since the data im getting can fill in more or less fields from my table.
as of right now im trying to build an event but I do not know the right syntax to use to create my event.
right now i have:
= if toggle.onclick ="yes" then
data.visible=true
else
data.visible=false
end if
in the After Update tab of the Event tab.
I hope that gives you an idea of what im trying to do.
I have this on a test form so the only objects are:
checkbox name "toggle"
textbox name "data"
the text box is default to not visible at the moment.
my goal is to have a list of check boxes and once they are checked their corresponding text box would appear on a refresh. this way the workers wont be intimidated by the amount of textboxes are on my current form. also will reduce the vast clutter on the current form.
By default, the 'Toggle' value will be True or False - not 'yes' or 'no'. Thus the following is what you need to toggle fields:
Private Sub Toggle_AfterUpdate()
If Me.Toggle = True Then
Me.Data.Visible = True
Else
Me.Data.Visible = False
End If
End Sub

VBA form to show cell value

I have an Excel VBA form to enter data into a worksheet.
Last column of my worksheet CC contains a formula which calculates some input fields. It is a very long though simple formula.
Is it possible that while I am entering the data in the form, a field in the VBA form itself keeps showing me running result of the inputs made based on the formula in the worksheet column CC?
I don’t know how to write that long formula in VBA so want to find out if there is a way around it.
If not possible, how about while the data has been entered in the form, there is a button CHECK RESULT. Clicking this button temporarily enters the form data to spreadsheet, populating CC cell and that result shows up as message box while the VBA data form is still open.
This result message box could have two buttons, CONFIRM ENTRY or CANCEL.
If cancel is clicked then the data entered in the spreadsheet is deleted. If confirm is clicked, then entered data stays.
Kind of urgent if someone can suggest a solution.
I have added image of my VBA form.
In the most basic manner to answer your sub question:
"Is it possible that while I am entering the data in the form, a field in the VBA form itself keeps showing me running result of the inputs made based on the formula in the worksheet column CC?"
Yes it's possible.
Asumming have a working formula anywhere in the sheet. Which you do according to your question.
Assuming your Sheet doesn't have a code like Application.Calculation = xlCalculationManual , to say your Sheet is in automatic calculation mode it will show you the running results.
You use key press or enter events in the Form to update the Sheet column CC
Your approach with buttons and message box seems fine. Why don't you give it a try and let us know with any issues you face.
Some hints:
UserForm1.Show vbModeless property
Allow worksheet access while user form is open
Editing spreadsheet while user form is open
How to show messagebox from cell changed event while user form is open?

How to update another text box while typing in access 2007 form?

I have a few text boxes which have to be filled with numeric values from 0 to 100. Below them there is another text box which stands for a total (the sum of the values from the text boxes above). How can I update the sum text box while typing in any of the other text boxes above?
If you are happy that the sum box updates after a box is updated (enter, tab or such like is pressed), then this can be done without any code. First, you will need to set the format of the textboxes to be summed to numeric, then the control source of the sum box becomes:
=Nz([text0],0)+Nz([text2],0)+Nz([text4],0)+Nz([text6],0)+Nz([text8],0) ...
Note the use of Nz, it may be possible to eliminate this by setting the default value property of the various textboxes to be summed.
A large set of controls that need to be summed in this way is often an indication of an error in the design of the database. You would normally expect this kind of thing to be a separate recordset, which could more easily be summed.
I know this is old, but Google didn't come up with much for this topic and this thread didn't really help either. I was able to figure out a very easy way to do this, so hopefully anyone else looking for this will find this helpful.
My need was for actual text as opposed to numbers, but the same applies.
To do what the OP is asking for you'll need at least 3 textboxes. 1 is the textbox you want to have updated each time you type, 2 is the textbox you will be typing in, and 3 is a hidden textbox.
Set textbox 1 to reference the value of the hidden textbox 3 in its control source:
="something in my textbox " & [textbox3]
In the OnChange event of textbox 2 right a line that will set the value of the hidden textbox 3 to the Text property of textbox 2 that you are typing in:
Private Sub textbox2_Change()
Me.textbox3.Value = Me.textbox2.Text
End Sub
Each time the value of the hidden textbox 3 gets updated, the calculation/reference in the displayed textbox 1 will be updated. No need to save caret locations or anything else mentioned in this post.
I was able to do this in Access 2007 by using the On Lost Focus event of the text box.
Just put something like this on the On Lost focus event of each text box that you want to be added , just make sure to set the default value of each text box to 0.
Me.Totals.Value = Me.Text1.Value + Me.Text2.Value + etc..
The moment you click on the next text box or anywhere as long as it loses focus, your sum will already be on the Totals box. You may add as many text boxes as you like, just include them in the code.
This is problematic due to the asinine requirement in Access that you have to set focus to text areas before you can get their value. I would recommend you change your design so that the text field is updated in response to a button click instead of on change.
If you want to go the update-on-change route, you would attach change events to each of the addend text fields. The event handlers would need to save the caret position/selection length, update the sum in the output text field, and restore the caret position. You need to save/restore the caret position because this is lost when the focus changes.
Here's an example for two text fields (txt1 and txt2). The output field is named txtOutput.
Private Sub txt1_Change()
Dim caret_position As Variant
caret_position = Array(txt1.SelStart, txt1.SelLength)
UpdateSum
txt1.SetFocus
txt1.SelStart = caret_position(0)
txt1.SelLength = caret_position(1)
End Sub
Private Sub txt2_Change()
Dim caret_position As Variant
caret_position = Array(txt2.SelStart, txt2.SelLength)
UpdateSum
txt2.SetFocus
txt2.SelStart = caret_position(0)
txt2.SelLength = caret_position(1)
End Sub
Private Sub UpdateSum()
Dim sum As Variant
sum = CDec(0)
txt1.SetFocus
If IsNumeric(txt1.Text) Then
sum = sum + CDec(txt1.Text)
End If
txt2.SetFocus
If IsNumeric(txt2.Text) Then
sum = sum + CDec(txt2.Text)
End If
txtOutput.SetFocus
txtOutput.Text = sum
End Sub