Solved

Calling a module in a form.

Posted on 1998-09-09
2
239 Views
Last Modified: 2010-04-30
How do you get a module to run in a form. Here is the code that I have in a module "If (KeyAscii = 13) Then SendKeys "{TAB}"".  I don't want to type it everytime and want to call it from a procedure.
0
Comment
Question by:matthewkwp
[X]
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
2 Comments
 
LVL 5

Accepted Solution

by:
yronnen earned 50 total points
ID: 1433863
in the module write
public sub ButtonClick(KeyAscii)
If (KeyAscii = 13) Then SendKeys "{TAB}"
end sub

in your keydown event on every form write
ButtonClick(KeyAscii)


0
 
LVL 1

Expert Comment

by:bharris1
ID: 1433864
First you can always 'copy and paste' code.  This has become one of my favorite helpful tips for coding.

Second, the KeyDown event doesn't give you the Ascii code for the key pressed it's in the KeyPress event.

Third, you should be able to call it like anything else.

IN FORM:
Private Sub Text1_KeyPress(KeyAscii As Integer)
    MyProcedure KeyAscii
End Sub

IN MODULE:
Public Sub MyProcedure(KeyAscii As Integer)
    If (KeyAscii = 13) Then SendKeys "{TAB}"
End Sub


0

Featured Post

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

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

Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

719 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