|
-
Jun 1st, 2000, 05:02 PM
#1
Thread Starter
Junior Member
I need to be able to take data from a text box and write it back to Access using Visual Basic 6. I have been using ADO throughout the project and have been able to update existing records in the database but I`m unsure of how to create new records using the data supplied in the text boxes, etc. Any help would be appreciated..
-
Jun 1st, 2000, 05:25 PM
#2
Fanatic Member
Hi spooked this is nice and easy to do.
Use the following code and it should sort out your problem
Code:
Public sub AddRecords()
Dim myRecordset As ADODB.recordset
Dim myConnection As ADODB.connection
Dim strSql As String
Dim strCon As String
strCon = 'put in your connection string here
Set myConnection = New ADODB.connection
Set myRecordset = New ADODB.recordset
myConnection.Open strCon
strSql = "SELECT * FROM tblTest" ' Replace this with your table
myRecordset.Open strSql,myConnection ,adOpenDynamic
myRecordset.addnew
'replace theese with your field names and you textboxes
myRecordset("SOMEFIELD") = txtsometextbox
myRecordset("SOMEFIELD1") = txtsometextbox1
myRecordset("SOMEFIELD2") = txtsometextbox2
myRecordset("SOMEFIELD3") = txtsometextbox3
myRecordset.Update
myConnection.close
Set myConnection = Nothing
Set myRecordset = Nothing
Hope this helps
Ian
Yeah, well I'm gonna build my own lunar space lander! With blackjack aaaaannd Hookers! Actually, forget the space lander, and the blackjack. Ahhhh forget the whole thing!
-
Jun 2nd, 2000, 12:35 AM
#3
Addicted Member
a little easier...
a quicker method with a little less code and a way quicker recordset transaction...
Code:
dbFields = Array("Text1", "Text2", "Text3")
dbValues = Array(Text1.Text, Text2.Text, Text3.Text)
adoRset.Open "table", adoConn, adOpenStatic, adLockOptimistic
adoRset.AddNew dbFields, dbValues
adoRset.Close
-
Jun 2nd, 2000, 12:42 AM
#4
PowerPoster
INSERT INTO Statement just enough
May be INSERT INTO statement is fastest to do this,
Code:
Dim xSQL$
Dim lngAffectedRcd&
Dim ADOConn As New ADODB.Connection
Set ADOConn = Bla...Bla...Bla...
xSQL = "INSERT INTO TblMyTable VALUES ('" & Text1.Text & "', '" & Text2.Text & "');"
ADOConn.Execute xSQL, lngAffectedRcd, adExecuteNoRecords
Assume TblMyTable only have 2 Text data fields.
[Edited by Chris on 06-02-2000 at 09:46 PM]
-
Jun 2nd, 2000, 10:22 AM
#5
If the TextBoxes are mapped to the datafields already why don't you just use ADO.addnew before they type the info in the boxes (it will even clear the boxes for a new entry) and then if they change records or add again it will automatically save the info or you can have a save button and just use ADO.update in the click event
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|