I have a worksheet with several different validation lists using named ranges on a different sheet. I realized that the cells using the ranges with blanks in them still allow the user to type in whatever they want. If there's no blank in that defined range, then the normal Excel error message pops up. Anyone know why this happens?
Ex:
Both types of validation lists are the default settings with "Ignore blank", "In-cell dropdown", and the Error Alert checked.
Some of my lists have spaces in between them but I would still like to restrict users to selecting only the choices provided by the dropdown.
Update:
I tried unchecking the "Ignore Blanks", but one minor issue this causes is that now the user can't press "Backspace" to clear the cell. They have to actually select one of the blank rows in the drop down list.
I discovered another issue which may only be specific to my code (not the example):
-if the cell already has an option selected
-the user tries to delete the cell via "Backspace" and the Excel error message pops up
-if I click Retry and click on the drop down list again, I get 3 of these:
-the error is from the Worksheet_Change sub and occurs despite me having an error handler within it
You need to uncheck the option for Ignore blank in the data validation dialog box.
Then Excel will give an error message when the user tries to enter data even if there are empty cells in the named range used by the data validation.
Related
I have a form frmDetail that contains several locked fields I want populated only when another form has been filled out, in the name of having some kind of standardization in my data. This other form frmSignOut is used to enter in a date and location that will populate the fields on frmDetail. frmSignOut also contains a subform subULookup that looks up users from a different table using an identifier number. The resulting last name, first name and phone # should also be passed to frmDetail. I also hope to combine first and last name somehow into a Last,First format.
My approach so far has been to open frmSignOut modally with acDialog and I inserted Visible=False into the On_Click event on frmSignOut. Then I try to reference my subform fields and set them to the desired fields on frmDetail. I finish by refreshing and then closing the dialog form.
Private Sub CmdSignOut_Click()
DoCmd.OpenForm("frmSignOut"),,,,,acDialog
If CurrentProject.AllForms("frmSignOut").isLoaded=True Then
Set Forms!frmSignOut!SubULookup.PhoneNbrTxt=Me.ContactNbrTxt
DoCmd.Close (acForm), ("frmSignOut")
Me.Refresh
End If
End Sub
I have only been able to get this far, trying to pull the first field PhoneNbrTxt. I can get frmSignOut to open, I put in data and when I click my 'close' command button I get run-time error 438: Object doesn't support this property or method.
The line highlighted is where I try to reference my subform field. I also have a 'Cancel' button added to frmSignOut that just closes the form, I have no errors there.
Again I'm completely new to Access without much prior experience in anything related, I'd appreciate any knowledge you guys can throw at me.
EDIT: I've been able to successfully pull the value to Me.ContactNbrTxt by adjusting my code to the below.
Me.ContactNbrTxt = Forms!FrmSignOut!SubULookup.Form!PhoneNbrTxt
It looks like the missing part was the Form! right before the control name, along with formatting this correctly and dropping Set.
Im still trying to work out how to combine first and last name before also pulling those to frmDetail, if anyone can help there.
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
If user changes/writes into excel sheet then he must click the validate button.If he changes data and tries to save/close excel,pop up must be show to the user. Simply I want to check whether used clicks validate button before closing the workbook. If a single letter is changed by user, user needs to click on validate button. After clicking on validate button ,if user again changes any data ,then too user must get warning that validate before saving/closing.
I don't want to write out all the code for you but what you'll need to do is create an on-change worksheet(Or workbook if you'd prefer) process that sets a custom worksheet attribute or your preferred method of storing a value persisting between sessions. That process will run when anything in the worksheet changes and will be able to set the value of your value so that you know "there has been a change, I am now not validated"
Then you need to create a before save process that checks to see if that value is "not validated" or "validated" (false or true or what have you). You set that process to break the save event and present an error message when the value is "not validated" and allow it when it is "validated".
Then you create a validate button/whatever and a process that sets the value to "validated" (may want to check and only change when the value is not already "validated" but that's up to you).
Then you'll have a set of processes where when the sheet/book changes, the value becomes invalid and saving is prevented. When the validate button is selected, the validate process changes the value to validated and saving is allowed again.
I have a drop down list column in an Excel worksheet to select a category. I have created a macro who replace the selected value by its ID after category selection (Worksheet_Change event).
Users have to fill the worksheet with ID but thank to this function, they just have to select a category in the drop down list and the ID replace the user choice.
It work well but I have a problem: if the user wants to write directly the ID in the cell, I have an error (Invalid value) and the macro is disabled.
How to do the difference in the Worksheet_Change between a change by the drop down list and a change by writing ? Or is there an other solution ?
Thank you !
If I understood correctly and you ARE using Data Validation:
Data Validation allows the user to optionally trigger an Error message if an incorrect value is entered (This error is the default setting). If you want to allow users to input information NOT in the list, turn off the error message by doing the following:
In the Data Validation dialog box, you will notice there are actually 3 tabs: Settings, Input Message, and Error Alert. Select the Error Alert tab, then UNCHECK Show Error Alert after invalid data is entered.
Does this resolve the problem?
Code in Form onLoad:
country_combo.RowSourceType = "Value List"
Code in a reset function:
Dim lListIndex As Long
With Me.country_combo
For lListIndex = .ListCount - 1 To 0 Step -1
.RemoveItem (lListIndex)
Next lListIndex<br/>
End With
Code to populate country combo:
*For n = 1 To numCountries*
*countryCombo.AddItem (countryRS.Fields("countryName"))*
*countryRS.MoveNext*
*Next n*
I'm having a problem that occurs AFTER the code to populate the country combobox runs. The values are there as I can run Debug.Print(countryCombo.Value) and it prints out the name of the selected country, but I can't see the values in the combobox at all. They're invisible, and as far as I know there is no visiblity property for specific items, unless I'm completely mistaken.
comboBoxError.png http://img110.imageshack.us/my.php?image=comboboxerror.png
I think you should probably use Access's GUI tools to do what you're looking for. In design mode, click on the field you are trying to populate, then click the "lookup" tab. You can then specify a table to populate the field with and your forms should automaticly update as well.
I've also seen what you describe here - as far as I can tell, it's a bug within Access (I was using 2007) that only occurs when you programatically mess with the contents of a combo box. It does not happen every time. The issue corrects itself if you highlight the text that is in the combo box.
I am experiencing a similar issue with Access 2003. Based on the selection of one combo box, the row source of a listbox is set to an SQL string Basically a SELECT DISTINCT [MyField_Selected] FROM MyTable. For some fields the values are visible in the list box and others it is not. The values are there however as I can access them via code. To make it more interesting it works fine in Access 2007.
Just found the resolution on another forum. Check the format property of the field(s) in question on the table. In my case, when Access 2007 created the table, it put an # format in there. I removed that and all works great!