Link to home
Start Free TrialLog in
Avatar of RandyTippetts
RandyTippetts

asked on

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

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

Avatar of jefftwilley
jefftwilley
Flag of United States of America image


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
Avatar of RandyTippetts
RandyTippetts

ASKER

I changed to the chr codes. It does not error but it does not place the decimal in the field either.
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
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.
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
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.

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.
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.
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.
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?
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.
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
OK. I'm with you now.

The code does not error but it is still ignoring the decimal.
if you type directly into the form TurboDetail, will it allow the decimal then?? This is beginning to not make any sense.
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.
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
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 ;-)

ASKER CERTIFIED SOLUTION
Avatar of jefftwilley
jefftwilley
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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...