Solved

input form fields into table ms access vba

Posted on 2007-11-28
6
4,527 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 2

Expert Comment

by:Chi Is Current
Comment Utility
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
Comment Utility
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
Comment Utility
Great!
0

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Suggested Solutions

The first two articles in this short series — Using a Criteria Form to Filter Records (http://www.experts-exchange.com/A_6069.html) and Building a Custom Filter (http://www.experts-exchange.com/A_6070.html) — discuss in some detail how a form can be…
Introduction When developing Access applications, often we need to know whether an object exists.  This article presents a quick and reliable routine to determine if an object exists without that object being opened. If you wanted to inspect/ite…
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…
In Microsoft Access, learn how to “cascade” or have the displayed data of one combo control depend upon what’s entered in another. Base the dependent combo on a query for its row source: Add a reference to the first combo on the form as criteria i…

744 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now