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 TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Inserting data into a table from a form

Status
Not open for further replies.

skaurd

Technical User
Jun 4, 2002
51
GB
HI

I have a form with no links to a table.

What I want to do is once a user has added data to this and clicked save, I want the data to be populated into a table.

All the data is going to be uploaded into one table

How would I do this please?

many thanks

S
 
Open a Recordset on the table and write to the table is the standard way.

If you want help in writing the code for the recordset then what version of Access are you using ?
and table name ?
Primary Key field name ?


G LS
 
hi G LS

I need help please in writing the code. I am using Access 97

Tabble to insert into is called company_details

fields are;
NameCoDet
Business_Description
RIC
Datastream_Code
Blomberg_Ticker
Sector
Earnings_Release_1
Earnings_Release_2
Earnings_Release_3
Web_address

Some of these can be null, but NameCoDet has to be filled in.

Primary key = Company_details_id (autonumber)

many thanks

S

 
Assuming that this is then a NEW record and the controls on the form have names that relate to the fields they hold data for - just with txt added to the front. ( I've done this to make it clear for you which are table!field names and which are form!control names. They can be the same name in each case if you want ) :-

Code:
Private Sub Button_Click()
Dim db As Database
Dim rst As Recordset

Set db = CurrentDb
Set rst = db.OpenRecordset("SELECT * FROM company_details")

rst.AddNew
rst!NameCoDet = txtNameCoDet 
rst!Business_Description = txtBusiness_Description 
rst!RIC = txtRIC 
rst!Datastream_Code = txtDatastream_Code 
rst!Blomberg_Ticker = txtBlomberg_Ticker 
rst!Sector = txtSector 
rst!Earnings_Release_1 = txtEarnings_Release_1 
rst!Earnings_Release_2 = txtEarnings_Release_2
rst!Earnings_Release_3 = txtEarnings_Release_3 
rst!Web_address = txtWeb_address

rst.Update
rst.Close

End Sub


As for the necessity of having valid data in the NameCoDet  control then have the form open with then button's enabled property set to false.

Then in the txtNameCoDet control's AfterUpdate procedure put

Private Sub txtNameCoDet_AfterUpdate()
If IsNull(txtNameCoDet) Then
    Button.Enabled = False
Else
    Button.Enabled = True
End If
End Sub




QED.

G LS
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top