Trying to send data from text boxes in vb to access

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I am developing a program in visual basic that contains an array of text
boxes, and i want to export the data from those boxes to a ms. access file
and create a new record each time the data is sent rather than overwrite the
data each time the user sends the data. Any help will be appreciated, thanks
 
JamesP:

My Response assumes:
1. The Text Boxes are in a form, "Form1"
2. The "File" is an access table, "Table1"
3. "Field1" is a field in Table1

Here is a procedure that, with tweeking, will append text box information
into an access table as a new record (There are of course, other ways to do
this).

Public Sub Add_Record_To_Table

Dim db as database
Dim rs as Recordset
Dim myText1 as string

Set db = currentdb

'Set the variable equal to the value of the text box in the form
myText1 = Forms!Form1![Text1]

Set rs = db.Openrecordset("Table1")

With rs

..Addnew
'Set the value of the field in the table (file) equal to the value of the
variable
!Text1 = myText1
..Update

..close

End With

Set rs = nothing
Set db = nothing

End Sub

Happy Hunting

Ross
 
When i run the code i get a compile error that says User-defined type not
defined, and i dont know what i'm doing wrong, this is my code up until the
program dies...

Option Explicit
Private Sub Command1_Click()
'My Response assumes:
'1. The Text Boxes are in a form, "Form1"
'2. The "File" is an access table, "Table1"
'3. "Field1" is a field in Table1

'Here is a procedure that, with tweeking, will append text box information
'into an access table as a new record (There are of course, other ways to do
'this).

Dim db As Database
Dim rs As Recordset
Dim myText1 As String

Set db = currentdb

'Set the variable equal to the value of the text box in the form
myText1 = Forms!Form2![Text1]

Set rs = db.Openrecordset("PitStopLog")

With rs

..Addnew
'Set the value of the field in the table (file) equal to the value of the
variable
!Text1 = myText1
..Update

..Close

End With

Set rs = Nothing
Set db = Nothing

End Sub
 
I am getting a compile error that says User-defined type not defined. Here
is my code. It highlights the Dim db as Database line as the error.

Option Explicit
Private Sub Command1_Click()

Dim db As Database
Dim rs As Recordset
Dim myText1 As String

Set db = currentdb

myText1 = Forms!Form2![Text1]

Set rs = db.Openrecordset("PitStopLog")

With rs

..Addnew
!Text1 = myText1
..Update

..Close

End With

Set rs = Nothing
Set db = Nothing

End Sub
 
Back
Top