sending data to table via form

datacontrol

Registered User.
Local time
Today, 21:05
Joined
Jul 16, 2003
Messages
142
Once again I seek the advice of this community on this project. I have set up a form for users to log / enter some data. When "apply" is pressed, I need some things to happen.

First off, I need a new record added to a certain table with all of the data inputted on the form.

My code in my form is generic, so I will explain what my form currently does. It has fields that pulls usernames and current dates from the system. Then, the user keys in three fileds, 2 of which are small number fileds and the third is a time field. I can forward my database if need be. I am coming along quite well thanks to all of you!

Here is the code in my form:

Option Compare Database

Private Sub OLEBound0_Updated()

End Sub

Private Sub Detail_Click()

End Sub

Private Sub Text2_BeforeUpdate(Cancel As Integer)

End Sub

Private Sub Text2_Enter()

End Sub
 
Firstly, and this is only my personal opinion, you should ALWAYS have OPTION EXPLICIT in your code, just beneath the OPTION COMPARE DATABASE. This means that you have to explicitly decalre any variables you use. Without it, Access just assumes that any you haven't declared are a variant.

Anyhow, to add a new record based on the info on the form, try:

DoCmd.RunSQL "INSERT INTO tblYourTable(Field1, Field2, Field3) VALUES (" & control1 & "," & control2 & "," & control3 & ")"

HTH,

Matt.
 
errors

Okay...thanks for the help...I am proceeding. Here is my current code. I get errors when pressing my command_apply button. "Variable not defined" I suppose I have my command button set up all wrong.

Thanks



Option Compare Database
Option Explicit


Private Sub OLEBound0_Updated()

End Sub

Private Sub Apply_Click()
DoCmd.RunSQL "INSERT INTO tblce(tblce_date, UserID, tblce_num_req_rec, tblce_num_req_pro, tblce_time) VALUES (" & Date & "," & test & "," & reqreceived & "," & reqprocessed & "," & time & ")"

End Sub

Private Sub Detail_Click()

End Sub

Private Sub Text2_BeforeUpdate(Cancel As Integer)

End Sub

Private Sub Text2_Enter()

End Sub


Private Sub date_BeforeUpdate(Cancel As Integer)

End Sub

Private Sub test_BeforeUpdate(Cancel As Integer)

End Sub

Private Sub reqreceived_BeforeUpdate(Cancel As Integer)

End Sub

Private Sub reqprocessed_BeforeUpdate(Cancel As Integer)

End Sub

Private Sub time_BeforeUpdate(Cancel As Integer)

End Sub
 
You need to reference your form:

Me.test ... Me.reqreceived ... if those are in fact, the names of the controls on the form ...
 
parameter value

hmmm...now I get an "error" when clicking apply.

enter parameter value dialog box. This is from a field where I am using a module to pull username - fOSUserName. If i enter my username in here (which is supposed to take place automatically) all info gets placed where it should be. Any ideas?


current code:

Option Compare Database
Option Explicit


Private Sub OLEBound0_Updated()

End Sub

Private Sub Apply_Click()
Dim db As DAO.Database
Dim rst As DAO.Recordset
Set db = currentdb()
Set rst = db.OpenRecordset("tblce", dbOpenDynaset)

DoCmd.RunSQL "INSERT INTO tblce(tblce_date, tblce_user, tblce_num_req_rec, tblce_num_req_pro, tblce_time) VALUES (" & Me.currentdate & "," & Me.user & "," & Me.reqreceived & "," & Me.reqprocessed & "," & Me.time & ")"

End Sub

Private Sub Detail_Click()

End Sub

Private Sub Text2_BeforeUpdate(Cancel As Integer)

End Sub

Private Sub Text2_Enter()

End Sub


Private Sub currentdate_BeforeUpdate(Cancel As Integer)

End Sub

Private Sub test_BeforeUpdate(Cancel As Integer)

End Sub

Private Sub FormHeader_Click()

End Sub

Private Sub reqreceived_BeforeUpdate(Cancel As Integer)

End Sub

Private Sub reqprocessed_BeforeUpdate(Cancel As Integer)

End Sub

Private Sub time_BeforeUpdate(Cancel As Integer)

End Sub

Private Sub user_BeforeUpdate(Cancel As Integer)

End Sub
 

Users who are viewing this thread

Back
Top Bottom