Good Morning.
I have a form where users are inputting hours, and the rounding function and everything works correctly, except when a user types 1,25 instead of 1.25, the hours jump to 125.00 instead of 1.25. Is there an easy fix? Or perhaps a statement I can throw in VBA to not accommodate for users to enter that in?
If anyone needs the code, let me know.
I appreciate your time and assistance, as I am new to Access.
Mark
Just to be sure, you don't want any values over 99, correct? I never tested my method with values over 1000 where Access would automatically put in the thousands separator (the comma) on its own, so I don't know how that would effect the practicality of my solution (or Adezii's for that matter), but if the values that you are entering are always going to be less than 99, then this won't be an issue. In fact, I personally would probably prefer Adezii's solution as it would fix it for them instead of just telling them that there was an error. You do also have the option of using the KeyDown event to test the character (including if the Shift, Control, or Alt keys were pressed at the same time) and then raise a warning if a comma was entered. The code that you had entered in post #4 should work in that event, but there isn't a way to keep the comma from being entered that is simple so you would be back to trusting the user to remove the comma. Thus I think that you would be better served (and less code entered) by using either ADezii's or my solutions as there would then be no way for the record to be saved with a comma having been entered.
10 1638
There are several ways to accomplish this. Let's suppose the Control containing these Values on your Form is a Text Box named txtValue. In the AfterUpdate() Event of txtValue you can place a single Line of Code that will convert any "," in the Value to a ".". - Private Sub txtValue_AfterUpdate()
-
Me![txtValue] = Replace(Me![txtValue], ",", ".")
-
End Sub
In the control's BeforeUpdate event, enter the following code (I will assume a control name of txtHours): - If InStr(me.txtHours, ",") > 0 Then
-
Cancel = True
-
MsgBox "This control cannot contain a comma."
-
End If
If a comma doesn't exist, the value returned will be 0. Otherwise, it will give the position of the comma in the string.
There might be another way that I haven't thought of, but this should work.
I have an idea that may not be as good as either of yours. I did some research and thought of the idea of prohibiting someone entering the KeyAscii of 44 (a comma). Is that possible? I don't want to set any values to 0, because as is the code works aside from the thousandths placeholder issue. I also implemented some formatting as a catch, changing the color of the box to red when value > 99.
Let me know what you all think about the KeyAscii solution and how would I implement it?
I was going to try -
If KeyAscii = 44 Then
-
MsgBox "Cannot enter a comma."
-
End If
-
But it kept coming up with an error saying KeyAscii was an unassigned variable.
- Private Sub ServiceHours_AfterUpdate()
-
On Error GoTo Err_Handler
-
-
-
-
Dim number, number2
-
-
number = Int(Me.[ServiceHours])
-
number2 = Me.[ServiceHours] - number
-
-
-
Select Case number2
-
Case 0
-
Me.[ServiceHours] = Me.[ServiceHours]
-
Case 0.0001 To 0.2499
-
Me.[ServiceHours] = Me.[ServiceHours] - number2 + 0.25
-
Case 0.2601 To 0.4999
-
Me.[ServiceHours] = Me.[ServiceHours] - number2 + 0.5
-
Case 0.51001 To 0.7499
-
Me.[ServiceHours] = Me.[ServiceHours] - number2 + 0.75
-
Case 0.76001 To 0.9999
-
Me.[ServiceHours] = Me.[ServiceHours] - number2 + 1
-
-
End Select
-
-
'Me![ServiceHours] = Replace(Me![ServiceHours], ",", ".")
-
-
Exit_Handler:
-
Exit Sub
-
Err_Handler:
-
MsgBox Error$
-
Resume Exit_Handler
-
End Sub
-
It did not work like this.
I also tried this -
If KeyAscii <> 44 Then
-
KeyAscii = KeyAscii
-
Else: KeyAscii = 46
-
End If
It didn't work.
The AfterUpdate event has no KeyAscii variable. Only the KeyPress, KeyUp, and KeyDown events have it defined.
NeoPa 32,556
Expert Mod 16PB
Mark,
You have two sensible suggestions available to you, but it seems you want to do it another way. This other way has very little going for it I'm afraid. I suggest you look at what's been suggested and give that some thought before trying to follow your own lead. Once you understand it better I'm confident you'll prefer the suggestions of those who have some experience in this field.
Just to be sure, you don't want any values over 99, correct? I never tested my method with values over 1000 where Access would automatically put in the thousands separator (the comma) on its own, so I don't know how that would effect the practicality of my solution (or Adezii's for that matter), but if the values that you are entering are always going to be less than 99, then this won't be an issue. In fact, I personally would probably prefer Adezii's solution as it would fix it for them instead of just telling them that there was an error. You do also have the option of using the KeyDown event to test the character (including if the Shift, Control, or Alt keys were pressed at the same time) and then raise a warning if a comma was entered. The code that you had entered in post #4 should work in that event, but there isn't a way to keep the comma from being entered that is simple so you would be back to trusting the user to remove the comma. Thus I think that you would be better served (and less code entered) by using either ADezii's or my solutions as there would then be no way for the record to be saved with a comma having been entered.
I apologize, I was out of town. Adezii, and all other users - I appreciate your time in assisting me solving this issue. ADezii, while your solution is logical, it did not work for me. MS Access recognized the "," as a thousands or hundredths place holder.
E.g: 3,2 went to 32.00
Hours are possible to exceed 99.
The only solution I found was setting a MsgBox when Hours > 99 that asks "Are you sure the hours are correct?"
I'm not sure why ADezzi's solution did not work, however, the end users are satisfied with the MsgBox popup.
Thank you all for your help, as a newb I appreciate it very, very much.
No problem. Glad to be able to help.
Sign in to post your reply or Sign up for a free account.
Similar topics
by: |
last post by:
Hi there,
I try to "reload" the value of a form - field called name each time the form
is being reloaded. I put this code in the php script:
session_start();
if (isset($name)){
$_SESSION =...
|
by: Marc Elser |
last post by:
Hi Everybody,
Can someone please tell me how to access the form name if there's a form
field named "name", for example:
<form name="myform">
<input type="text" name="name" value="Marc">...
|
by: Wouter |
last post by:
Hi,
I had a javscript what does the follow. When a checkbox is yes then i will
see a form field. When a checkbox is no i dont see the form field.
Can somehelp me for that script ?
Greets...
|
by: Pavils Jurjans |
last post by:
Hello,
I have bumped upon this problem: I do some client-side form processing
with JavaScript, and for this I loop over all the forms in the
document. In order to identify them, I read their...
|
by: Dooza |
last post by:
Hi there,
I was wondering if anyone had come across some javascript that would
allow me to have a chart of say 20 music tracks, and be able to move
each track up and down the chart using up/down...
|
by: Earl Teigrob |
last post by:
I want to allow users to input html (via a rich text box) or directly, into
a form field, save it in a data store and then output that html to the
browser, but not allow cross-site scripting.
...
|
by: ross |
last post by:
The following gives an error:
<?php
$super-man=100;
?>
Parse error: parse error, unexpected '=' in /test.php on line 2
I understand that the "-" sign is seen as an operator.
is there a...
|
by: blackrunner |
last post by:
ERROR in my Query?!
ERROR:
Element GESCHLECHT is undefined in FORM.
i think everything ok. Maby somebody can help me here
Element GESCHLECHT is undefined in FORM.
The error occurred...
|
by: Wolfman |
last post by:
Hi gang!
I've been searching for a solution to this problem extensively but nothing really hits the mark.
I have a descriptive popup page that contains a PayPal order button. The normal PayPal...
|
by: Peter Laman |
last post by:
In my app I need to dynamically generate a series hyperlinks. Each
hyperlink's action must be to focus a field in a <form>. I created the
following function to create such a link (the argument is a...
|
by: Faith0G |
last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
| | |