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

How to Get data from Text box to Access

Status
Not open for further replies.

mustang98

Technical User
Dec 7, 2004
12
US
I'm using the following code to copy information from a text box in word to a database in Access. I don't get any errors but none of the information in the text boxes gets entered into my database. Can someone help me with this?

Thanks

Dim db As Database
Dim rs As Recordset

Selection.GoTo What:=wdGoToBookmark, Name:="clientsTop"
Selection.Text = FirstName.Text & " " & LastName.Text
Selection.GoTo What:=wdGoToBookmark, Name:="address"
Selection.Text = Address.Text & ", " & City.Text & ", " & State.Text & ", " & ZipCode.Text

'Insert Information into the Database

Set db = OpenDatabase("C:\LoneStar\db1.mdb")
' open the database
Set rs = db.OpenRecordset("Client Info", dbOpenTable)
' get all records in a table

With rs
.AddNew ' create a new record
' add values to each field in the record
.Fields("First Name") = FirstName.Text
.Fields("Last Name") = LastName.Text
.Fields("Home Number") = HomeNo.Text
.Fields("Email Address") = Email.Text
.Fields("Home Address") = Address.Text
.Fields("City") = City.Text
.Fields("State") = State.Text
.Fields("Zip") = ZipCode.Text

End With
 
With rs
Try this

.AddNew ' create a new record
' add values to each field in the record
.Fields("First Name") = FirstName.Text
.Fields("Last Name") = LastName.Text
.Fields("Home Number") = HomeNo.Text
.Fields("Email Address") = Email.Text
.Fields("Home Address") = Address.Text
.Fields("City") = City.Text
.Fields("State") = State.Text
.Fields("Zip") = ZipCode.Text
.update

End With
regards


Zameer Abdulla
 
WOW..thank you so much. That worked!
Can you explain to me why the .update is necessary?

Thanks again!
 
I learned it from VB6. Normally VB6 has all the forms Unbound to the table (if you are using code). An unbound form need the instruction to update the record to the table.
So you have to open the recordset dynamically (sql or what ever way) and Edit or AddNew to the existing table and instruct to update it.
For editing a record also the same method
Code:
.Edit
'recordset description
.update
regards

Zameer Abdulla
Visit Me
Where to pay your [purple]Tsunami[/purple] relief donations?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top