how to inter or delete data from table using VBA

elgali_84

New member
Local time
Yesterday, 23:30
Joined
Nov 5, 2009
Messages
1
hi all

how can i use VBA to inter or delete date to Access Table ??
 
hi all

how can i use VBA to inter or delete date to Access Table ??

****************************************************
using recordset
------------------------------------------------------------------
Dim rstUserData As New ADODB.Recordset
Dim rstSqlStr As String
Dim recCount As Single

rstSqlStr = "Select * from UserData"
If rstUserData.State = adStateClosed Then rstUserData.Open rstSqlStr, CurrentProject.Connection, adOpenKeyset, adLockOptimistic

recCount = rstUserData.RecordCount

rstUserData.AddNew
rstUserData.Fields(0) = "First Name"
rstUserData.Fields(1) = "Second Name"
rstUserData.Update

------------------------------------------------------------------
where rstUserData is record set (which is linked to the table with sqlstr)
and UserData is table in the database.
*****************************************************

to delete data, depends on whether you want to delete the entire data in the table or on a particular condition.

Similarly create an Sql Delete statement and run according to requirement.
 
A lot easier to create an Sql Statement and then execute it. Less confusing and less lines of code. Example:

Code:
Dim sMySql as string
 
sMySql = "INSERT INTO tblTableName (Field1, Field2) " & _
             "VALUES (" & me.txtbox1 & "," & me.txtbox2 & ")"
currentdb.execute sMySql
 

Users who are viewing this thread

Back
Top Bottom