Store Textbox value to table

  • Thread starter Thread starter Rohit Thomas
  • Start date Start date
R

Rohit Thomas

I am creating a form that has a unbound texbox. I would
like the value inputted into the texbox to be saved to a
table. The value would be a single record that would be
replaced every time the form is accessed and the data is
inputted into the textbox. If anyone can point me in the
right direction or provide some sample code, I would
appreciate it.

Thanks,
Rohit Thomas
 
You can use the following code to store the data written into your textbox
on the the LostFocus event of your textbox:

Private Sub myTextBox_LostFocus()
Dim con as Connection
set con = CurrentProject.Connection
con.Execute "INSERT (FieldName) INTO myTable VALUES '" & textBox1 & "'"
End Sub

and to load the value entered previously into the textbox as a default text
when the form is loaded:

Private Sub Form_Load()
Dim con as connection, rs as recordset
Set rs = CreateObject("ADODB.Recordset")
rs.Open "Select FieldName From myTable"
If rs.recordCount > 0 then 'means that there is a data stored
textBox1=rs.Fields("FieldName")
End If
End Sub
 
Just set the field in your recordset=to the value of the
textbox.

RecSetObject!TheField=me!TextBox.Value

or RecSetObject.Fields(index).Value=me!TextBox.Value

You really don't need the Me reference, but I use it so
the intellisense list drops down and I don't have to
worry about typos.


Good Luck,

Scott
 
Back
Top