Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Can't produce a decimal in a keypad form (The numbers work fine)

Posted on 2009-07-16
19
281 Views
Last Modified: 2013-11-28
I have created a form "KeyPad" using controls as number keys. I am using the sample 1 code iin the "on click" option of the form. I then call it using the sample 2 code from within the fields using the "on got focus" option.

This woks terrific for the numbers but when I press the "." decimal, the plus, minus, or divide sign they are ignored or I get a 2113 runtime error. The minus sign displays but to the left of any number I type regardless of the order it was entered.

I can live without the others but I need to have the decimal working for this form. I have to do a brief demo of the whole app this afternoon. It would be great to have the solution by then. Can anyone help me out?

Thanks
Sample 1: 
Forms(Left$(Me.OpenArgs, InStr(Me.OpenArgs, ";") - 1))(Mid$(Me.OpenArgs, InStr(Me.OpenArgs, ";") + 1)) = Forms(Left$(Me.OpenArgs, InStr(Me.OpenArgs, ";") - 1))(Mid$(Me.OpenArgs, InStr(Me.OpenArgs, ";") + 1)) & "1"  {or 2 or 3, etc.}
 
Sample 2: 
DoCmd.OpenForm "KeyPad", , , , , , "MyForm;MyField"

Open in new window

0
Comment
Question by:RandyTippetts
  • 10
  • 9
19 Comments
 
LVL 34

Expert Comment

by:jefftwilley
ID: 24870357

Sample 1:
Forms(Left$(Me.OpenArgs, InStr(Me.OpenArgs, ";") - 1))(Mid$(Me.OpenArgs, InStr(Me.OpenArgs, ";") + 1)) = Forms(Left$(Me.OpenArgs, InStr(Me.OpenArgs, ";") - 1))(Mid$(Me.OpenArgs, InStr(Me.OpenArgs, ";") + 1)) & "1"  {or 2 or 3, etc.}
 
Sample 2:
DoCmd.OpenForm "KeyPad", , , , , , "MyForm;MyField"

use Chr(46) for a period
Chr(43) plus
Chr(45) Minus

etc..
J
0
 
LVL 1

Author Comment

by:RandyTippetts
ID: 24870454
I changed to the chr codes. It does not error but it does not place the decimal in the field either.
0
 
LVL 34

Expert Comment

by:jefftwilley
ID: 24870510
can you show me the code that builds the string in Sample 1?

You're building a string on each button click I assume...this should be a syntax issue..nothing big
0
Three Reasons Why Backup is Strategic

Backup is strategic to your business because your data is strategic to your business. Without backup, your business will fail. This white paper explains why it is vital for you to design and immediately execute a backup strategy to protect 100 percent of your data.

 
LVL 1

Author Comment

by:RandyTippetts
ID: 24870639
That is the entire code. Each button in the KeyPad form has the sample 1 code in the "on click" option. The only change to that code is at the end where I place the desired character in quotes.  When I call this form from a numeric field in another form it accumulates numbers I click on the keypad form within the numeric field on the other form.

I undstand the concept of what it's doing but I don't completely understand how that line of code does it. The code came from another solution on this board about creating a touch screen keypad.
0
 
LVL 34

Expert Comment

by:jefftwilley
ID: 24870921
Here's a small sample calculator that may lend a hand. (Attached)

So you're trimming the openargs and putting the character at the end. What is the string supposed to look like as you type it?

(openarg = 1234)   and you're adding "." at the end

something like that?

and this does not work?

Forms(Left$(Me.OpenArgs, InStr(Me.OpenArgs, ";") - 1))(Mid$(Me.OpenArgs, InStr(Me.OpenArgs, ";") + 1)) = Forms(Left$(Me.OpenArgs, InStr(Me.OpenArgs, ";") - 1))(Mid$(Me.OpenArgs, InStr(Me.OpenArgs, ";") + 1)) & chr(46)  
Calculator.zip
0
 
LVL 1

Author Comment

by:RandyTippetts
ID: 24871085
I have looked at the calculator before and it produces a result I can place in a field but that is not what I am trying to do.

Here is what should happen:

I open a form that has several fields.
I click on one of the numeric fields to give it focus
The KeyPad form pops up modal
As I select numbers on the keypad form each number adds to the field as if I am typing them in.
When I hit the "enter" key on the KeyPad form the form closes and the result of my entries on that form remain in the numeric field.
When I click on another numeric field the process repeats repeats for that field.
Numbers entered are going to be similar to: 2.134, 9.65, 47, 3.1418, etc.

The whole thing work very slick with the exception of that darn decimal point being ignored.

0
 
LVL 34

Expert Comment

by:jefftwilley
ID: 24871278
This may work out

Private Sub cmdOne_Click()
Forms!ONE.Form.MyNumber = Forms!ONE.Form.MyNumber & Me.cmdOne.Caption
Forms!ONE.Form.Refresh
End Sub

Private Sub cmdPeriod_Click()
Forms!ONE.Form.MyNumber = Forms!ONE.Form.MyNumber & Me.cmdPeriod.Caption
Forms!ONE.Form.Refresh
End Sub


I'm using the caption of the buttons on my KeyPad form as values to add to a text field on the underlying form.

The refresh was just to I could see when the data appears.
0
 
LVL 34

Expert Comment

by:jefftwilley
ID: 24871295
you may also check the formatting of the fields where your numbers are being written. Make sure that your controls allow decimals and that you have the Decimal Placing set to Auto.
0
 
LVL 1

Author Comment

by:RandyTippetts
ID: 24873520
I am not sure I understand the code.  I replace the form name with my KeyPad form name and the command click with mine as well but I am getting a run-time 2465 error when I execute. That is an application or object defined error.
0
 
LVL 34

Expert Comment

by:jefftwilley
ID: 24879273
The form is actually the underlying form, the one that you're parsing out of the OpenArgs in your code. All I've demonstrated was the fact that on a button's click event, you can pass it's caption value vs a hard coded value. I set up two forms. On one, I put a text box. This is what receives the numbers as I type them on my second form (my keypad). On each click, I append the value in the text box with the value of the caption on the button that I'm pressing on my keypad.

Isn't this what you're doing as well?  

Does the formatting of the numeric field on your main form allow decimals?
0
 
LVL 1

Author Comment

by:RandyTippetts
ID: 24880460
Yes. The field I am attempting to write accepts decimals and takes keyboard input with no problems. Can you show me an example using my name struture?

The keypad form is named KeyPad.
The control on that form for the decimal is called Command11.
The form I am writing to is called TurboDetail.
The field I am trying to write is called BalanceTS.

Thank you.
0
 
LVL 34

Expert Comment

by:jefftwilley
ID: 24880520
Make the caption of the Command11 on the KeyPad form button a "."

on the command11 On_Click Event on your Keypad form


forms!TurboDetail.Form.BalanceTS = forms!TurboDetail.Form.BalanceTS & me.Caption
forms!TurboDetail.Form.Refresh
0
 
LVL 1

Author Comment

by:RandyTippetts
ID: 24880674
OK. I'm with you now.

The code does not error but it is still ignoring the decimal.
0
 
LVL 34

Expert Comment

by:jefftwilley
ID: 24880705
if you type directly into the form TurboDetail, will it allow the decimal then?? This is beginning to not make any sense.
0
 
LVL 1

Author Comment

by:RandyTippetts
ID: 24880774
Yes. Any entry from the keyboard into that form and that same field works as planned.

If I type in 2.345 on the keyboard, I get 2.345 in the field.
If I type it in the KeyPad form, the end result in the field is 2345

You are certainly right. It does not make sense.
0
 
LVL 34

Expert Comment

by:jefftwilley
ID: 24880915
Without getting too chatty here...This is simple string manipulation. You are passing the form and control successfully.

I think what's happening is, you can't simply add a decimal at the end of a numeric value without something behind it.

Here's what I would suggest...and it seems to be a workaround, but will work.

Create an unbound textbox on your form. When you're adding data from your keypad, update that unbound field.

Now when you hit <Enter> on your keypad, add a step to update the numeric field from your OpenArgs with the number in the unbound box.

What this will allow you to do is type the number as "Text" which doesn't care if you have 123.   or 123.40

See where I'm coming from?

J
0
 
LVL 1

Author Comment

by:RandyTippetts
ID: 24881061
The decimal doesn't work even as the first character, but I see where you are going with this.

My KeyPad is used to update three fields on the form, making the KeyPad Enter the trigger to write the field impractical, but I should be able to use the AfterUpdate or LostFocus events on the unbound textbox to update the related fields shouldn't I?

I'll set up a test form and try it. I'll keep you posted ;-)

0
 
LVL 34

Accepted Solution

by:
jefftwilley earned 500 total points
ID: 24881107
This approach should work


Openargs Control = "BalanceTS"

KeyPad Button Click:
forms!TurboDetail.Form.UnboundControl = forms!TurboDetail.Form.UnboundControl & me.Caption
forms!TurboDetail.Form.Refresh

Enter Button Click:
forms!TurboDetail.Form.BalanceTS = forms!TurboDetail.Form.UnboundControl

Yes?
0
 
LVL 1

Author Closing Comment

by:RandyTippetts
ID: 31604275
Sorry for the delay. The form works as planned in a text box. From there it is a simple matter to convert and populate the numeric field.
Thanks for your help...
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Regardless of which version on MS Access you are using, one of the harder data-entry forms to create is one where most data from previous entries needs to be appended to new records, especially when there are numerous fields and records involved.  W…
Phishing attempts can come in all forms, shapes and sizes. No matter how familiar you think you are with them, always remember to take extra precaution when opening an email with attachments or links.
Familiarize people with the process of utilizing SQL Server views from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Access…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

828 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question