compile error on sub for ascii key

I have a public sub in 2 different forms.
main form
and
subform

Public Sub ConvertToCaps(KeyAscii As Integer)

' Converts text typed into control to upper case

   Dim strCharacter As String
   
   ' Convert ANSI value to character string.
   On Error GoTo ConvertToCaps_Error

   strCharacter = Chr(KeyAscii)
   ' Convert character to upper case, then to ANSI value.
   KeyAscii = Asc(UCase(strCharacter))

   On Error GoTo 0
   Exit Sub

ConvertToCaps_Error:

    MsgBox "Error " & Err.Number & " (" & Err.Description & ") in procedure ConvertToCaps of VBA Document Form dbo_t_redbook_pricing_escalation_detail_subform"

End Sub

Open in new window


When i try to compile my database i get a "byref argument type error".. ?

Need to get rid of it. please
fordraiders
LVL 3
FordraidersAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

NorieVBA ExpertCommented:
How are you calling the sub?
0
FordraidersAuthor Commented:
Private Sub CALLER_DSM_RACFID_Change()
ConvertToCaps KeyAscii
End Sub

calling this way
0
NorieVBA ExpertCommented:
Where is the value for KeyAscii coming from and how is it declared?
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

FordraidersAuthor Commented:
sorry, here is the calling
Private Sub CALLER_DSM_EMAIL_KeyPress(KeyAscii As Integer)
ConvertToCaps KeyAscii
End Sub
0
NorieVBA ExpertCommented:
Do you actually have code like this?
Private Sub CALLER_DSM_RACFID_Change() 
    ConvertToCaps KeyAscii 
End Sub

Open in new window

If you do that could be the cause of the error.
0
FordraidersAuthor Commented:
yes,
I added.
Dim KeyAscii As Integer
0
NorieVBA ExpertCommented:
I'm not following, are you still getting the error?

You posted 2 different subs, one where the data type of KeyAscii wasn't set and one where it was set to Integer.

Then one where the data type wasn't set would cause the error you describe.
0
FordraidersAuthor Commented:
this was causing the error
Private Sub CALLER_DSM_RACFID_Change()
ConvertToCaps KeyAscii
End Sub

changed to

Private Sub CALLER_DSM_RACFID_Change()
Dim KeyAscii as integer
ConvertToCaps KeyAscii
End Sub
0
crystal (strive4peace) - Microsoft MVP, AccessRemote Training and ProgrammingCommented:
try:
Public Sub ConvertToCaps(ByVal iKeyAscii As Integer)

instead of passing by reference (whose value can be changed and returned), ByVal (by value) makes a copy of the value for use in the procedure

also changed the name to iKeyAscii, in case there is a name issue

have an awesome day,
crystal
0
Gustav BrockCIOCommented:
There is no error. I can compile and run your code:

Private Sub Test_KeyPress(KeyAscii As Integer)

    ConvertToCaps KeyAscii
    
End Sub


Public Sub ConvertToCaps(KeyAscii As Integer)

' Converts text typed into control to upper case

   Dim strCharacter As String
   
   ' Convert ANSI value to character string.
   On Error GoTo ConvertToCaps_Error

   strCharacter = Chr(KeyAscii)
   ' Convert character to upper case, then to ANSI value.
   KeyAscii = Asc(UCase(strCharacter))

   On Error GoTo 0
   Exit Sub

ConvertToCaps_Error:

    MsgBox "Error " & Err.Number & " (" & Err.Description & ") in procedure ConvertToCaps of VBA Document Form dbo_t_redbook_pricing_escalation_detail_subform"

End Sub

Open in new window

So, possibly the code module is corrupted. Delete the offending code and retype it, and it will work.
0
FordraidersAuthor Commented:
gustav, its the "Change" event causing the error .
0
Gustav BrockCIOCommented:
Don't use that. This event is not for key-presses.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
crystal (strive4peace) - Microsoft MVP, AccessRemote Training and ProgrammingCommented:
adding on to Gustav's comment ...

the Change event is for detecting a change to perhaps read what is there so far and look up information.

Code cannot change the value in a control until the AfterUpdate event happens.

have an awesome day,
crystal
0
FordraidersAuthor Commented:
THANKS TO ALL
0
Gustav BrockCIOCommented:
You are welcome. Have a nice weekend!
0
crystal (strive4peace) - Microsoft MVP, AccessRemote Training and ProgrammingCommented:
you're welcome, Brett ~ happy to help
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Access

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.