469,645 Members | 1,138 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,645 developers. It's quick & easy.

Automatic Data Entry into Form Fields - How?

I'm using Access 2003, on Windows XP Pro.

I have a subform which is launched from a command button on my main form. When this form opens, I have 2 fields which I have inserted VBA Code into to capture the information in two of the fields on the main form, so I can sync and track the data entered into the subform to the record on the mainform.

In the "Got Focus" event of each of the two fields I've inserted the following code, to capture the data from the main form:

Expand|Select|Wrap|Line Numbers
  1.  Me.ActiveControl = Forms!F_KSM_Contacts_Sc!SM_Contacts_ID 
and

Expand|Select|Wrap|Line Numbers
  1.  Me.ActiveControl = Forms!F_KSM_Contacts_Sc![SM_S-PersonRef] 
This works great to capture the data, however it requires me to have the user tab through these two fields in order to have the data be pulled into the fields in question. I want to automate this so that these fields capture that data automatically upon the form opening, but I don't know how to write the syntax in such a way as to make this happen.

I have tried using SendKeys to try and send a "Tab" command using:

Expand|Select|Wrap|Line Numbers
  1.  SendKeys vbKeyTab, 0  
in several properties, including the "On Open" property of the form (thinking that on open it would send two tab keys, which, if the two fields were the first two in the tab order it would tab through them, and thus the data would be pulled in. However this does not work.

Any suggestions for the easiest way to do this? I'm a beginner at VBA and I have a bit of trouble translating the syntax definition into a working syntax statement, so please give me some comments in any suggested code, as a guide. Thanks
Sep 28 '06 #1
1 4679
Tanis
143 100+
Avoid SendKeys at all costs. I think ther may be an easier way.Why not refer to the fields implicitily. Something like this behind your command button. Not too sure about the syntax for subforms though.
Expand|Select|Wrap|Line Numbers
  1.  DoCmd.OpenForm "frmSubFormName", acNormal, "", "[PrimaryKeyField]=[Forms]![frmMainForm]![PrimaryKeyField]", acAdd, acNormal
  2.  
  3. Forms![frmSubForm]![PrimaryKeyField] = Forms!frmMainForm![PrimaryKeyField]
  4.  
  5. Forms![frmSubForm]![YourControlName1] = Forms!frmMainForm![YourControlName1]
  6.  
  7. Forms![frmSubForm]![YourControlName2] = Forms!frmMainForm![YourControlName2] 
Sep 29 '06 #2

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

1 post views Thread by Trent | last post: by
4 posts views Thread by =?Utf-8?B?Q2FybGluIEFuZGVyc29u?= | last post: by
reply views Thread by gheharukoh7 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.