Solved

input form fields into table ms access vba

Posted on 2007-11-28
6
4,553 Views
Last Modified: 2013-11-28
I have an Access form with several data stored in Labels.  I would like to input the data contained within these labels into a target table called "target_table" within the same acccess dbase.  All the data will go into the same column, but in different rows.  I was wondering how to go about doing this in VBA, to kick off a function when the user selects a button on the form?

Thanks,
Vishalarya
0
Comment
Question by:vishalarya
  • 4
  • 2
6 Comments
 
LVL 2

Accepted Solution

by:
Chi Is Current earned 500 total points
ID: 20371717
Vishalarya ~

"Labels", do you mean text boxes on the form?

Try:

1) Setting the record source for the form to the destination table.
2) Use "text boxes" instead of labels on your form.
3) Set the control source for each text box on the form to the corresponding field on your table.

Jacob
0
 

Author Comment

by:vishalarya
ID: 20371728
No labels are fine since it's simple text data.  Actually can't I just use DoCmd.RunSQL query and reference my caption for the field.  As I'm not too familiar with SQL, does anyone know the code.  For example:

Form name: vtest
caption name: label47

label47 contains text = "abcd"

I want to insert label47's caption into table "target_table".  What would be the INSERT INTO statement for doing so?

Thanks,
Vishalarya
0
 
LVL 2

Expert Comment

by:Chi Is Current
ID: 20371741
If you are using a form that is not bound or cannot be bound, you can do this by placing the data in a recordset that updates to your destination table.

dds110 provides this example on solution: http://www.experts-exchange.com/Microsoft/Development/MS_Access/Q_20814041.html?sfQueryTermInfo=1+data+form+from+tabl+unbound


Sub YourButton_Click()
Dim db As Database
Dim rst As Recordset

Set db = CurrentDb
Set rst = db.OpenRecordset("Table_To_Be_Updated")

With rst
  .AddNew
  .Fields("Table_Field_Name1") = Me.ControlName
  .Fields("Table_Field_Name2") = Me.ControlName2
  '...
  .Update
End With

rst.Close
db.Close

Set rst = Nothing
Set db = Nothing

End Sub

0
The Eight Noble Truths of Backup and Recovery

How can IT departments tackle the challenges of a Big Data world? This white paper provides a roadmap to success and helps companies ensure that all their data is safe and secure, no matter if it resides on-premise with physical or virtual machines or in the cloud.

 
LVL 2

Expert Comment

by:Chi Is Current
ID: 20371754
For this to work you will need to store the data in 'text box' controls on your form.  I don't think you'll be able to reference 'labels'.
0
 

Author Comment

by:vishalarya
ID: 20371768
no jacob you are wrong.

THe following code works:

DoCmd.runSQL ("UPDATE target_table set col2 = '" & label47.caption & "' where col1 = 'one'")

no need for text boxes.
0
 
LVL 2

Expert Comment

by:Chi Is Current
ID: 20371787
Great!
0

Featured Post

Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

Question has a verified solution.

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

Regardless of which version on MS Access you are using, one of the harder data-entry forms to create is one where most data from previous entries needs to be appended to new records, especially when there are numerous fields and records involved.  W…
Phishing attempts can come in all forms, shapes and sizes. No matter how familiar you think you are with them, always remember to take extra precaution when opening an email with attachments or links.
Basics of query design. Shows you how to construct a simple query by adding tables, perform joins, defining output columns, perform sorting, and apply criteria.
In Microsoft Access, learn how to use Dlookup and other domain aggregate functions and one method of specifying a string value within a string. Specify the first argument, which is the expression to be returned: Specify the second argument, which …

803 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