473,288 Members | 1,726 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,288 software developers and data experts.

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 4829
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

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

Similar topics

9
by: Don Seckler | last post by:
I am trying to set up a PHP web page so I can enter data into a database. I created a form: <form action="admin_news_insert_processor.php" method="post" name="frm_Insert_News"...
0
by: Dave | last post by:
Hi, I'm creating a form based on a table. This table has fields including UniqueID (auto numbered and different for each entry), Track (3 different types), ClassYear (4 different years), and...
4
by: m_houllier | last post by:
STUDENT TABLE StudentReference Student Name etc ATTENDANCE TABLE AttendanceID CourseID StudentReference
1
by: Trent | last post by:
I am in the design phase of a new database and am having a devil of a time with a subform. I have three tables that relate to problem - Suppliers tbl, Customers tbl and a SuppliersCustomers tbl....
6
by: Wayne | last post by:
I am designing a database which needs approximately 50 fields per record. The database user requires data entry to be via a single screen. If I follow good database design practice and split the...
2
by: filbennett | last post by:
Hi Everyone, I'm generally unfamiliar with Access form design, but have programmed Cold Fusion applications for a couple of years. I'd like to build a data entry form in Access that allows the...
1
by: NumberCruncher | last post by:
Hi All, I am struggling with setting up my first system of tables, forms,and reports, and could use your help! I am setting up a database to keep track of the production of a produced item. The...
4
by: =?Utf-8?B?Q2FybGluIEFuZGVyc29u?= | last post by:
I have a large classic ASP web application which needs to now support chinese character entry (I don't have to worry about the UI yet - the data entry people can read english). Other than changing...
2
kcdoell
by: kcdoell | last post by:
Hello: I have four tables: tblDivision tblWorking_Region tblCredit_Region tblForecast (This is the main data entry table for all forecasting records) tblDivision has the following fields:
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.