Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

I'm addicted to using SENDKEYS..

Status
Not open for further replies.

chaft

Technical User
Feb 7, 2008
55
GB
Throughout my work I have continuously used Sendkeys to run code that I use a lot. I'm aware that this a poor way to design my database product but I don't know how to run the same segments of code without using Sendkeys to run command buttons. Can someone explain how I might run segments of code without having to put them behind every control?

I thought of using a module but I do need to refer to specific controls in the form to check for text inputs.

I would like to know better ways of coding.

cheers


 
As you can directly control most of the values on the screen, sendkeys is not that useful.

Instead of:
myfield.setfocus
sendkeys "new value"


Try:
myfield.value="new value"

What else are you using sendkeys for?


SeeThru
Synergy Connections Ltd - Telemarketing Services
 
chaft said:
Can someone explain how I might run segments of code without having to put them behind every control?
I don't get what you mean here. You put code behind the controls if they need to do something specific. It's not necessary for every control. Textboxes, for example, don't usually have code behind them.

Perhaps you can give some examples where you typically use SendKeys? We may then show you the VBA method of doing the equivalent.

 
IMHO there are very,very few reason I can think of to ever use send keys. I would break the habit to improve your coding.
 
It's hard to describe but this is a scenario that I need to get out of from using SENDKEYS

I'm in a subform. I've just deleted the last record and so now I want the subform to hide. But in order to refresh my main form of the changes I use the sendkeys to press the 'Save' button on my main form (which I have put code behind which does a thorough check of all my images and controls that need to be corrected.) The code behind the 'Save' button updates the images to say there are no records and ensures the subform is hidden and the right tab and images are showing.

Now I have many subforms. If I were to put the code that I have behind the 'save' button in every subform instead my access file will be big.





 
You can move the code to an easily accessible module, or as a step to breaking the addiction, you can run the code itself:

Forms!Form1.Button1_Click

Take it step by step, you can beat this :)
 
I agree with MajP! SendKeys should only be used if you have something that is mission critical and you can find no other way to accomplish it, and this is seldom the case!

The Missinglinq

Richmond, Virginia

There's ALWAYS more than one way to skin a cat!
 
As Remou said you can create public functions with parameters that will be accessible from anywhere in the db. That will be maintainable easily.



________________________________________________________
Zameer Abdulla
Help to find Missing people
 
Ok i've been googling the public variable option and I'm outta my depth as to putting one in a module and calling upon it when i Need it. Now I'm sure that's the best solution as I can feel my old teacher whacking me over the head with a cane saying something about public declarations and modules.

Could you explain how it works a bit more? cuz I'm almost there. The force is strong with this solution if I can comprehend it.





 
Assuming that the Save button is on a form named frmMain, and that when you created the button's action it generated a Private Sub cmdSave_Click subroutine - you could change "Private" to "Public" and code "frmMain.Save_Click" on your subform.
 
How are ya chaft . . .

We can help you better if you post the code in your save button!

Calvin.gif
See Ya! . . . . . .

Be sure to see thread181-473997
Also faq181-2886
 
I chickened out of the module idea, although I think one day I will have to sit down and learn it. I used ramou's idea which is my middle way solution and it worked well. I eliminated tons of sendkeys operations.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top