Store Textbox value to table

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
 
W

Warrio

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
 
S

Scott

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top