Modules & VBA :: Create Disable Alphabetic Keys Function Based On Case Statement
Jul 31, 2015
Details:
I have a Profile form that tracks the expiration date for each client's various certifications. These dates are set up in the Short Date format in the table design of Access.
Problem:
When a user accidentally presses an alphabetic key while updating an expiration date, an Access error message is triggered. This is confusing to my users as these messages are written in Access lingo. I would rather that nothing occurs at all. I wrote a case statement to disable each letter of the alphabet and applied it to the On Key Down Event for each expiration date control on my Profile form to solve this problem, but this must be applied to 28 separate controls. I would rather call a function that disables alphabetic keys for each date control in my form when called.
Questions:
How do I transform my Disable Alphabetic Keys Case Statement into a function that I can call for each expiration date control? I know that when writing a function certain variables have to be declared and/or initialized.
Also, will I need to create a function to re-enable alphabetic keys or is this unnecessary because the disable alpha keys function will only be called for specific controls, not the entire form?
What I Have Tried:
I have tried copying and pasting my Disable Alphabetic Keys Case Statement into a module to attempt to create a function, but it needs work.
Below I have included 2 types of code:
(1) The original On Key Down code applied to each date control on my form
(2) The same code written as an attempt at a function
Original Profile Form Code to Disable Alphabetic Keys in the On Key Down event for each date control
Private Sub txtCert1ExpDate_KeyDown(KeyCode As Integer, Shift As Integer)
Select Case KeyCode
'All message box text is for me to test the code, not for the user to see
Case vbKeyA
MsgBox ("you pressed the A key")
I have a lengthy CASE statement in my database that displays specific text in a field based on the value of another. Simple stuff but for some reason it randomly will not work on certain values, and never the same one twice. Is there a commonly known cause for this? I have verified that the spelling and spacing etc. are correct in my code so that shouldn't be causing the problem.
Hi everyone, please help, i am in depserate need here. Am i right in thinking nested IF functions are limited to 7 variables, i need to choose from 12, so i need to use something different
it seems like a CASE function could do what i want it to, but i really have no clue where to start, shall i enter this into a query criteria box, or on the form itself ina new field box...??
Can you give a few hints as to what the code would look like, i have two fields, obviously. One is 'lesson_type' and one is 'cost' i want the cost to change depending on what is selected in the lesson type box.
I have a boolean array, foundState(3), whose 4 elements correspond to 4 variables describing conditions that will dictate what action is taken upon closing a form.
There are only 6 possible outcomes for the array, and they can be divided into just 4 cases:
Case {T,T,T,T}
Case {T,T,T,F} OR {T,T,F,F} OR {T,T,F,T}
Case {T,F,F,F}
Case {F,F,F,F}
What the proper syntax would be for this if I'm trying to create a "Select Case" statement for these 4 cases.
My problem now is about evaluating the result of that query in order to calculate quarterly and annual performances. The query returns correctly:
1) NULL - when I don't have values in the given month 2) 0 - when one of the components of the performance formula is 0 3) value (positive or negative) which can include any positive or negative value
In order to calculate the quarterly values I need the performance of the last month in the quarter and the first month in the quarter. My monthly values are stored in columns so say for Quarter 1, I would need something like this:
Code: [mar]/[jan]-1
As you might have thought, the problems come when I have NULL or 0 values. Let me give you a couple of examples.
[jan] is NULL [feb] is a value [mar] is a value
Than my formula would have been
Code: [mar]/[feb]-1
Second case:
[jan] is 0 [feb] is 0 [mar] is 0
In this case I would like the formula return '-' because I want to be able to spot the case in which the quarterly performance is 0 because the initial values were 0 from the case in which the performance was actually 0 (i.e., say [jan] = 101 and [mar] = 101 then performance is 0 which is different from having [jan] and [mar] = 0 thus performance '-').You can combine the three states (NULL, 0, value) with the three months and find many combinations (I have found 27 relevant ones).
I initially thought to use SWITCH in SQL to evaluate the 27 combinations but I found out that SWITCH would evaluate non more than 15 conditions. So I guess the solution should be use a function in VBA which does what I was about to do with SWITCH in SQL.
I have built a test function which evaluates the numerator of my formula using only two cases (CASE 1: all variables have a value <>0, and CASE 2: the first month is null, the second is 0 and the third a value). Here the code:
Code: Function evaluate_s(Var1, Var2, Var3) As Double Select Case Var1 Case Is <> 0
[code]....
My main question here is what is wrong in the syntax of my function. Why is not correctly evaluating at least the two cases in my function? I always get 0 for all records.
I am trying to get a Case Statement to evaluate multiple conditions. Example: below when I get diagnosis code 20400 and the age_at_diagnosis is 40 the code is basically ignoring the second condition of the Case "And rs![Age_At_Diag] < 18". How do I get the code to recognize both conditions?
Code:
Private Sub cmd_Update_Conditional_Codes_Click() Dim rs As DAO.Recordset Dim rs2 As DAO.Recordset
I have an issue with this case select below. The DelayStart is time so lets say I put in the debug window
?DatePart("h", #04:00pm#)
The result would be 16 which is correct BUT the issue is my second shift starts at 04:01pm and the result is still 16 untill 5pm. How do I fix this so I get the correct shifts? Im guesing use something other than DatePart but what?
Code: Public Function getShiftForRecord(DelayStart As Variant) On Error Resume Next Select Case DatePart("h", DelayStart) Case 6 To 16 'Daylight 6:00am - 4:00pm
I'm trying to update some field value depending two string field using a function with if and case, function below:
Code: Private Function checkDATI(tipotransazione As String, tipovendita As String) As String Dim r As String r = "" If tipotransazione = "VENDITA" Then Select Case tipovendita
[code]...
And then when I call this function in a command button event as:
I would like to select a case depending on the output of a function.
This function tests the syntax of the reporting month.
If the syntax is fine nothing should be done further in the main sub else it should return to the Input window for the reporting month.
Somehow it doesn't work out.
Code: Public Function RepMonthCheck(rep_date As String) as Boolean If Len(rep_date) <> 6 Or Left(rep_date, 2) > 12 Or Left(rep_date, 2) < 1 Then MsgBox ("Reporting rep_date is not in the correct format = mmyyyy") Return False ElseIf Right(rep_date, 4) > 9998 Then MsgBox ("No forecast available for year 9998")
I am trying to add various values based on Select Case to the value of field. The problem I face is that each time when I get different Case in select statement, the value of the field rather changing adds the value on top.
Code: Private Sub ProductID_AfterUpdate() Dim qflPrice As Variant Dim db As DAO.Database Dim rs As DAO.Recordset Dim sqlQry As String Dim instID As Integer
I have a fully functioning frmLogin that appears when the database opens. After correctly logging in, it takes you to the appropriate switchboard. The problem is that I set autokeys to allow F1 to automatically open the switchboard, but I don't want users to hit this to bypass my login screen. The reason for keeping the switchboard open is to force the user to close the database using the switchboard(eventually I want to limit the user to only the forms that I have created in a split database).
My other option that I tried first was writing a module that would detect when all forms are closed, then open the switchboard. But I kept getting Error91 and got frustrated/stopped attempting this method. Using the hotkey gives the user a similar functionality, but less conveniently so(since its not an automated process, etc.).
I would like to have a combo box that doesn't show the drop-down arrow when the user selects it. You say, doesn't that defeat the purpose of the combo box?
Well, look. In a form I have a datasheet (in a subform) that only displays data, so it is locked from editing. Within the datasheet is a field that contains a combo box with a row source from a linked table, and the control source of that combo box is the primary key. Essentially I'm utilizing the combo box because it is smart, and allows me to display linked data: this combo box contains two columns, and I set the first column's width to "0" so that it would only display the field I want. I didn't use a subform because, in datasheet view, subform fields are not displayed in the linear fashion I need, but instead go hide under the "+" button for each record.
So, even though everything is locked from editing, the combo box arrow still appears when the user clicks on the combo box field, and I don't want it to. It's just misleading to the user. Anyone know how to disable the arrows? Or, if you catch my drift, do you know of another simple solution?
I'm not a keen programmer in case you couldn't figure that out. If you've got any VB tips then let me know.
I am trying to run the following query and getting an error. It looks like its because of the Case Statement.
SELECT Role.RoleID, Objects.ObjectID, CASE MID(Objects.ObjectName, 4, 2) CASE 'SR' 0 CASE ELSE 2 END AS AccessType FROM Role, Objects WHERE (Role.RoleID > 2115)
Hello, I'm attempting to use a case statement in order to select fields from a column that have names and addresses mixed. I'm wanting to select only the fields that contain names. For example some fields start with an address of "1998 Sky Rd" or PO BOX, or Suite at the beginning of the field. I would like to first select all fields with names in the field and then use an update statement to move/switch fields to another column. The only problem is that I can't seem to get this query to work. Please help!!!
Thank you!!!!!!!!!
SELECT address1, name3=address1 as expr1
Case [address1]
When mid([address1],1,1) Like [A-Z] then [address1] When [address] is null then "" When [address] = "" then "" Else 'Null" End,
How can I use function keys to get it to do a constant thing throughout all my forms etc. e.g. to nominate eg "F3" to save data or "F5" to go back a page etc.
I am trying to make a field in a query which displays a date based off of the criteria below. I tried nesting IIF statements but I couldn't get it to work so I tried a Case WHEN statement.
CASE WHEN [Appfrom] Is Null & [Fundfrom] Is Null THEN "7/7/1999" WHEN [Appfrom] Is Null & [Fundfrom] IS NOT NULL THEN [Fundfrom] WHEN [Fundfrom] Is Null & [Appfrom] IS NOT NULL THEN [Appfrom] WHEN [Fundfrom] IS NOT NULL & [Appfrom] IS NOT NULL THEN "7/7/1999" END
Here is the IIF statement
IIf(IsNull([Appfrom] And [Fundfrom]),"7/7/1999",(IIf(Not IsNull([Appfrom]) And IsNull([Fundfrom]),[Appfrom],(IIf(IsNull([Appfrom]) And Not IsNull([Fundfrom]),[Fundfrom],"7/7/1999"))))))
Neither one works and have no idea how to fix it. Any ideas would be greatly appreciated. Thanks.
Here is my CASE WHEN statement in SQL. What would the If statement be in MS access?
CASE WHEN LEN(Serial) = 9 THEN Serial WHEN LEN(CAST(Serial as Varchar(255))) = 8 THEN '0'+Serial WHEN LEN(CAST(Serial as Varchar(255))) = 7 THEN '00'+Serial WHEN LEN(CAST(Serial as Varchar(255))) = 6 THEN '000'+Serial ELSE 'Error' END AS NewSerial
Can someone simplify my feeble scratching at a Case Select statement, please?
I have two fields in a table (True/False): IsActive and IsDefault
I would like to convert some If...Else...Then statements to a Case Select statement which details what should be done when any of the possible states of the two fields exist.
Semi-Psuedo example in the (subform) Form_Current Event: With Me If !IsActive = True And !IsDefault = False Then Do Something on the Parent form ElseIf !IsActive = True And !IsDefault = False Then Do Something Else on the Parent form ElseIf !IsActive = True And !IsDefault = True Then Do Something Else Again on the Parent form Else Do Something Entirely Different End If End With
What blows my mind is the Select Case Expression bit. I can't figure out how to write this. Any help is greatly appreciated.
If I write a select case statement for a field X i.e. 6 to 7 for example will this:1. Select any fields X where the number is greater than or equal to 6 but less than (and not including) 7B. Select any fields X where the number is greater than or equal to 6 but includes decimels of 7 i.e. 7.5 ORC. Select any fields X where the number is greater than or equal to 6 but includes but literally only includes cases where the the whole number 7 appears>I only ask because in an example in a book I am looking at says:Case 10000 to 20000......Case 20001 to 30000I would have through the word "to" means until but not including but in this case the field that equals 20000 would never be selected?
Where do I go to make the F keys perform a particular function when moving around in a form, like "go the the last page of the form" or move to the top, or to page two etc. Thanks.
I have a complex IF Statement within VBA. When I step thru the code the if statement variables should return true but instead treats it as False. See '>>>> this happens on the 2nd Pass of a Do Loop Statement, the First Loop the if Statement Returns True
Variable Values:
Record 1 contractNo: 00001634 nfld: 33.40% nTier6: 30.00%
Record 2 contractNo: 00001634 nfld: 137.52% nTier6: 28.50%
so the 2nd if should be true but it acts as false an moves to next If statement.
Code:
If nfld = Format(0, "Percent") Then nOvrAmt = 0 BkOvrCalc = nOvrAmt GoTo cont: '>>> ElseIf nfld > nTier6 Then nOvrAmt = rs.Fields("TotalNetUSExp") * rs1.Fields("T6E").Value