Numpad in a form

daniel2126

Registered User.
Local time
Yesterday, 22:14
Joined
Jul 25, 2013
Messages
20
I am working on create a numpad on a form and I have the following code but the decimal "." is not working and I having the following error..

Compile error : Argument not optional

here is the code and I color in red where the error comes from.

Option Compare Database
Option Explicit

Private Function TypeAlphaNum(strKey As String) As String
Screen.PreviousControl.SetFocus
Me.Controls(Screen.ActiveControl.Name).SelStart = Nz(Len(Me.Controls(Screen.ActiveControl.Name)), 0)
Me.Controls(Screen.ActiveControl.Name).SelLength = 0
Me.Controls(Screen.ActiveControl.Name).Value = Me.Controls(Screen.ActiveControl.Name).Value & strKey
End Function
Private Sub Key_0_Click()
TypeAlphaNum "0"
End Sub
Private Sub Key_1_Click()
TypeAlphaNum "1"
End Sub
Private Sub Key_2_Click()
TypeAlphaNum "2"
End Sub
Private Sub Key_3_Click()
TypeAlphaNum "3"
End Sub
Private Sub Key_4_Click()
TypeAlphaNum "4"
End Sub
Private Sub Key_5_Click()
TypeAlphaNum "5"
End Sub
Private Sub Key_6_Click()
TypeAlphaNum "6"
End Sub
Private Sub Key_7_Click()
TypeAlphaNum "7"
End Sub
Private Sub Key_8_Click()
TypeAlphaNum "8"
End Sub
Private Sub Key_9_Click()
TypeAlphaNum "9"
End Sub
Private Sub Key_Backspace_Click()
Screen.PreviousControl.SetFocus
Me.Controls(Screen.ActiveControl.Name).SelStart = Nz(Len(Me.Controls(Screen.ActiveControl.Name)), 0)
Me.Controls(Screen.ActiveControl.Name).SelLength = 0
Me.Controls(Screen.ActiveControl.Name).Value = Left(Me.Controls(Screen.ActiveControl.Name).Value, Len(Me.Controls(Screen.ActiveControl.Name)) - 1)
End Sub
Private Sub Key_Decimal_Click()
If InStr(TypeAlphaNum, ".") Then
Exit Sub
Else
TypeAlphaNum = TypeAlphaNum + "."
End If
End Sub


Private Sub Command100_Click()
On Error GoTo Err_Command100_Click

DoCmd.RunCommand acCmdSaveRecord
Exit_Command100_Click:
Exit Sub
Err_Command100_Click:
MsgBox Err.Description
Resume Exit_Command100_Click

End Sub
 
Well, you're missing the Start argument of InStr(), but I think it's optional. You certainly can't call the function that way. You're testing the function as if it were a variable. The function requires an input parameter, thus your error. Wouldn't you pass the decimal to the function?
 
Also I think the If statement will complain since you are not returning a Boolean. If you put in InStr(TypeAlphaNum, ".")= 0 then it should keep the If statement happy.
 
Also I think the If statement will complain since you are not returning a Boolean. If you put in InStr(TypeAlphaNum, ".")= 0 then it should keep the If statement happy.

Thanks for your answer but I'm still having the error TypeAlphaNum. Any suggestion ?... thanks !
 
YOu are trying to run the function recursively by calling itself from within, which here is nonsense.

To return a value from a function, with or without arguments, you write INSIDE THE FUNCTION

JustTheNameOfMyFunction=WhateverTheValueYouWIshToAssignToIt

OMG just saw also this:

TypeAlphaNum = TypeAlphaNum + "."


You cannot assign a value to a function by using =.


Find a tutorial on using functions in VBA and work through the basics.
 
YOu are trying to run the function recursively by calling itself from within, which here is nonsense.

To return a value from a function, with or without arguments, you write INSIDE THE FUNCTION

JustTheNameOfMyFunction=WhateverTheValueYouWIshToAssignToIt

OMG just saw also this:

TypeAlphaNum = TypeAlphaNum + "."


You cannot assign a value to a function by using =.


Find a tutorial on using functions in VBA and work through the basics.

I was using the format "JustTheNameOfMyFunction=WhateverTheValueYouWIshToAssignToIt" suggested but the assigned value did not come. The idea of this "." is to represent the decimal for further numerical operations.

Please forget the... TypeAlphaNum = TypeAlphaNum + "."

In other words the question will be how I can create the decimal point on my numpad ?
 
You can't use the function that way. You could change the value of the textbox that the function changes, but I'm curious why you don't use the function the way you do for other values. Can you post the db here?
 
You can't use the function that way. You could change the value of the textbox that the function changes, but I'm curious why you don't use the function the way you do for other values. Can you post the db here?

Thanks for your reply. Here is the DB.
 

Attachments

I think you're running into a situation where a numeric field will drop the decimal if there are no digits after. Plus your data types are Long Integer, which can't hold a decimal anyway. If you put focus in the comments field, your code works just fine. One option that comes to mind is using unbound textboxes for your numeric input, and copy those to hidden bound textboxes in your save button.
 
Did you miss post 9?
 

Users who are viewing this thread

Back
Top Bottom