Hi can anyone tell me how to add a new record to a table in Access from within VB code and also how to check to see if a file exists already on a hard drive? Any help on this be greatly appreciated. Thanx in advance
u can check ur record using a query like
dim db as database
dim a as recordset
dim b as recordset
set b=db.openrecordset("emp"
set a=db.openRecordset("select * from emp where empno=urs new value"
if a.reccount>=1 then
msgbox "Record already exists"
else
b.addnew
b("name"="names"
'insert ur field values
end if
There is 2 ways of inserting row in tables. Webspy shows one of them. Note, however that not all providers support .recordcount, and that the cursortype should be 'static' to support .recordcount. You also need to update the recordset after .addnew:
---------------------------------------------------------
Dim Rst As ADODB.Recordset, con As ADODB.Connection
Set con = New ADODB.Connection
con.Open YourConnectionString
Set Rst = New ADODB.Recordset
Rst.Open "SELECT * FROM MyTable", con, adOpenKeyset, adLockOptimistic
Rst.AddNew Array("name", "title", Array("sunaj", "Technical user"
Rst.Update
Rst.Close
Set Rst = Nothing
con.Close
Set con = Nothing
---------------------------------------------------------
The other method is to use SQL:
---------------------------------------------------------
Dim con As ADODB.Connection
Set con = New ADODB.Connection
con.Open YourConnectionString
con.execute "INSERT INTO Mytable(name,title) VALUES ('sunaj','Technical user')"
con.Close
Set con = Nothing
---------------------------------------------------------
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.