save textbox value back to table

G

Guest

I am trying to save a text box content back to a table.

I currently have a listbox that queries a previous button using this query.

SELECT tblSpecifics.SpecificID, tblSpecifics.SpecificName,
tblSpecifics.txtDescription
FROM tblSpecifics
WHERE (((tblSpecifics.CategoryID)=[forms]![Main]![cboCategory]));

Then, I have it set to make a textbox equal column 2, to display the memo
field containing the data

Private Sub cboSpecifics_Click()
Me.txtDescription.Value = Me.cboSpecifics.Column(2)
End Sub

When a user is finished modifying the data, I want it to automatically save
back to the table, no buttons to click, or user intervention, but I'm having
troubles doing so.
I'm trying this, but with no results.

Private Sub txtDescription_Exit(Cancel As Integer)
'Dim db As Database
Dim rst As Recordset
Set rst = CurrentDb.OpenRecordset("Select * from tblSpecifics where
SpecificName=" & Me.cboSpecifics)
rst.Edit
rst!txtDscription = txtDescription
rst.Update
rst.Close
Set rst = Nothing
End Sub

Any assistance would be appreciated, no rush, this is a learning curve for me.
 
M

Marshall Barton

Jonathon said:
I am trying to save a text box content back to a table.

I currently have a listbox that queries a previous button using this query.

SELECT tblSpecifics.SpecificID, tblSpecifics.SpecificName,
tblSpecifics.txtDescription
FROM tblSpecifics
WHERE (((tblSpecifics.CategoryID)=[forms]![Main]![cboCategory]));

Then, I have it set to make a textbox equal column 2, to display the memo
field containing the data

Private Sub cboSpecifics_Click()
Me.txtDescription.Value = Me.cboSpecifics.Column(2)
End Sub

When a user is finished modifying the data, I want it to automatically save
back to the table, no buttons to click, or user intervention, but I'm having
troubles doing so.
I'm trying this, but with no results.

Private Sub txtDescription_Exit(Cancel As Integer)
'Dim db As Database
Dim rst As Recordset
Set rst = CurrentDb.OpenRecordset("Select * from tblSpecifics where
SpecificName=" & Me.cboSpecifics)
rst.Edit
rst!txtDscription = txtDescription
rst.Update
rst.Close
Set rst = Nothing
End Sub


Don't use the Exit event for this. You only want to write
it back to the table if the user changes the description, so
use the AfterUpdate event instead.

I think the problem is that your where clause is using the
combo box's value, which is normally the ID field. Double
check it, but, as long as the ID field is numeric, you
probably want to use:

where SpecificID =" & Me.cboSpecifics)
 
G

Guest

You are correct, thank you.
This resolved my problems.

Private Sub txtDescription_AfterUpdate()
Dim rst As Recordset
Set rst = CurrentDb.OpenRecordset("Select * from tblSpecifics where
SpecificID=" & Me.cboSpecifics)
rst.Edit
rst!txtDescription.Value = txtDescription
rst.Update
rst.Close
Set rst = Nothing
End Sub
 

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

Top