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

inserting a row from form to Table?

Status
Not open for further replies.

Koaz

Programmer
Nov 26, 2002
15
SG
Hi all,

I know that inserting the data to table, had to use sql statement, but I am not sure how do i execute them? After writing all this.

Sub DB_Connect()
Dim db
Dim sql As String
db = "C:\Documents and Settings\HoRiZoN\Desktop\Eleave_convert.mdb"
DataConn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source =" & db
DataConn.Open
End Sub

Sub update_table()
Dim sql As String
sql = "Insert Into Application (nric, name, leave frdate, leave todate, email, total date, leave type )" _
& "Values ('" & strEmpNo & "','" & strEmpName & "','" & frmDate & "','" & lastDate & "','" & noDays(frmDate, lastDate) & "','" & typeNo & "')"

End Sub

Thanz for your help. I am still a beginner.
 
I would put all the code in the subroutine. otherwise you have to share the variables globally.

try this
Sub update_table()
Dim Conn2 As ADODB.Connection
Dim Rs1 As ADODB.Recordset

Dim sql As String

Set Conn2 = New ADODB.Connection
Set Rs1 = New ADODB.Recordset

Conn2.Open "Provider = Microsoft.Jet.OLEDB.4.0;Data Source = C:\Documents and Settings\HoRiZoN\Desktop\Eleave_convert.mdb"

sql = "Insert Into Application (nric, name, leave frdate, leave todate, email, total date, leave type )" _
& "Values ('" & strEmpNo & "','" & strEmpName & "','" & frmDate & "','" & lastDate & "','" & noDays(frmDate, lastDate) & "','" & typeNo & "')"

Rs1.Open sql, Conn2, adOpenStatic, adLockOptimistic
' Note: do normal rs1! or rs1. stuff from now on
'like Rs1!fieldname
' Rs1.addnew

' close it this way
Set rs1 = nothing
Set Conn2 = nothing
End sub DougP, MCP
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top