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")

[Code] .....

View Replies


ADVERTISEMENT

Modules & VBA :: CASE Statement - Display Specific Text In A Field Based On Value Of Another

Sep 22, 2014

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.

View 2 Replies View Related

CASE Function Or IF Statement

Feb 28, 2006

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.


LESSON TYPE ----------- COST

Beginner 1hour ----------- 15
Beginner 2hour ----------- 29
Beginner 3hour ----------- 42
Test Retake 1hour -------- 13
Test Retake 2hour -------- 25
Test Retake 3hour ---------36
Disqualified Retake 1hour -- 25
Disqualified Retake 2hour -- 49
Disqualified Retake 3hour -- 72
Advanced 1hour ---------- 10
Advanced 2hour ---------- 19
Advanced 3hour ---------- 27

Is it possible to do that, change the cost correpsonding to what one is entered in lesson_type...??? And where do i put it??? What do i do with it??

Thanks, dragon2309

View 4 Replies View Related

Modules & VBA :: Using Select Case Statement With Array?

Jun 26, 2014

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.

View 7 Replies View Related

Modules & VBA :: Select Case Function

Aug 17, 2014

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.

View 8 Replies View Related

Modules & VBA :: Trying To Get Case Statement To Recognize Multiple Conditions

Sep 8, 2014

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

[code]...

View 1 Replies View Related

Modules & VBA :: Case Select Public Function

Jun 4, 2014

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?

'Daylight 6:00am - 4:00pm
'Afternoon 4:00pm - 2:00am
'Midnight 2:00am - 6:00am

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

[Code] ....

View 11 Replies View Related

Modules & VBA :: Field Update Using Function With Case

Jun 10, 2015

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:

Code:
MsgBox (checkDATI(Me.CausaleMov, Me.txt_tipomov))

It's not update those field.

View 6 Replies View Related

Modules & VBA :: Case Differentiation Through Return Value Of A Function

Jan 3, 2014

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")

[Code] ....

View 3 Replies View Related

Modules & VBA :: Adding Various Values Based On Select Case To Value Of Field

Oct 1, 2014

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

[Code] .....

View 5 Replies View Related

Forms :: Any Way To Disable Hot Keys At Login Form

Nov 16, 2013

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.).

View 4 Replies View Related

Queries :: IIF Statement Expression - Create Alias Column Based On Data From Two Fields

Jun 20, 2013

I am writing a very complex 'if statement' query expression. I need to create an alias column based on data from two data fields.

Here's the logic:

True: If [PP] = "WG" or "WS" or "WL" and If [GR] > 10 Then "Skilled" or
[GR] Between 6-9 Then "Semi - Skilled" or [GR] <6 Then "Unskilled"

False: "GS"

View 2 Replies View Related

Can You Disable Combo Box Arrows? If Not, Any Other Ideas For My Case?

Apr 13, 2005

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.

View 7 Replies View Related

Case Statement

May 23, 2005

Hi,

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)

Can you give me suggestions plzzz

Thanks,

View 2 Replies View Related

Case Statement

Dec 19, 2007

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,

FROM Exercise1;



:confused:

View 9 Replies View Related

Using Function Keys

Sep 1, 2004

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.

View 2 Replies View Related

CASE Statement In SELECT

Mar 21, 2007

Does anyone know if its possible to perform a CASE Statement in a SELECT statement in Access and if so what the syntax is? Thanks in advance.

View 9 Replies View Related

CASE WHEN Statement Problem

Aug 8, 2007

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.

View 4 Replies View Related

Case Statment To If Statement

Apr 29, 2008

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

Thanks for your help!

View 5 Replies View Related

Sql Case Statement In Access??!?

Jan 12, 2006

hey
Is it possible to use sql case statements in access ?
I have used them in sql server all the time and they are really useful!

I mean statements like this one:

"SELECT iOrderID,dOrderDate,iTotalBeforeVat,iShipTotal,iVa tTotal,iTotal,
CASE sOrderStatus WHEN '9' THEN 'Canceled' END FROM tTmpOrderRpt"

thanks!

View 4 Replies View Related

Not The Best At Case Select Statement Writing...

May 14, 2007

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.

View 6 Replies View Related

Select Case Statement - General Q

Feb 6, 2008

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?

View 14 Replies View Related

Setting Function For F Keys In A Form

Sep 4, 2005

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.

View 2 Replies View Related

Modules & VBA :: If Statement Not Return True Based On Data

Mar 14, 2014

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

[Code] .....

View 1 Replies View Related

Syntax Error -- Case Statement In Query

Jan 16, 2008

Hi,

I received syntax error for the following statement

SELECT
CASE [File Type]
WHEN 'Security' THEN 'SEC'
WHEN 'Admin' THEN 'ADM'
END AS FT
FROM [tbl_Core Non-Core]


please advise

thanks

Alice

View 3 Replies View Related

Modules & VBA :: Total Based On Combination Of Criteria - Compound If Statement

Aug 15, 2013

I'm trying to get a total based a combination of criteria. Here's my issue:

If ([Vendor Billed Amount] > 650 $ and $ [Excess Fee Approved] = "Yes") then
[Payment to Vendor] = [Vendor Billed Amount]
else
If ([Vendor Billed Amount] < 650 $ and $ [Excess Fee Approved] <> "Yes") then
[Payment to Vendor] = [Vendor Billed Amount]
else
endif
endif

I think I'm missing an argument with the nested If statement.

View 3 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved