Save text box to table?

N

Niniel

Hello,

How can I save an unbound text box directly to a specific record in a table?
I can specify the right record via ActivityID and QuestionID. The field I
want to save to is called "Note".

Right now I am moving the content of the unbound text field [located on the
parent form] to a hidden text field on a continuous subform that is based on
the table that is to store the information [which is not the table the parent
form is based on], so it is saved that way.
The problem with that approach is that the right record has to be the
current record on the continuous subform for the text to be saved in the
correct place. If somebody were to edit only the text field later, the
information will end up in the wrong place.

I can read the record into my text field
Me.Parent.NoteText = DLookup("[Note]", "tblActivityAnswers",
"[ActivityID] = " & Me.Parent.[ActivityID] & " AND [QuestionID] = 12")
but don't know how to write to it.

Any suggestions?

Thank you.
 
V

Van T. Dinh

You can use either an UPDATE Query or a Recordset to update the "Note"
Field. The SQL should be something like:

UPDATE [tblActivityAnswers]
SET [Note] = Forms!MainForm!NoteText
WHERE [ActivityID] = Forms!MainForm.[ActivityID]
AND [QuestionID] = 12

You can use the RunSQL method to run the above SQL. Alternatively, you can
use the Execute method of the database object (but you need to resolve the
references to the Form's Controls to explicit values before passing the SQL
to JET for execution)

--
HTH
Van T. Dinh
MVP (Access)



Niniel said:
Hello,

How can I save an unbound text box directly to a specific record in a
table?
I can specify the right record via ActivityID and QuestionID. The field I
want to save to is called "Note".

Right now I am moving the content of the unbound text field [located on
the
parent form] to a hidden text field on a continuous subform that is based
on
the table that is to store the information [which is not the table the
parent
form is based on], so it is saved that way.
The problem with that approach is that the right record has to be the
current record on the continuous subform for the text to be saved in the
correct place. If somebody were to edit only the text field later, the
information will end up in the wrong place.

I can read the record into my text field
Me.Parent.NoteText = DLookup("[Note]", "tblActivityAnswers",
"[ActivityID] = " & Me.Parent.[ActivityID] & " AND [QuestionID] = 12")
but don't know how to write to it.

Any suggestions?

Thank you.
 
N

Niniel

Thank you very much, running an update query via runsql works nicely.

I have just one request - would you mind also explaining the other method
you mentioned, ie. the "recordset" method?

Thanks a lot.
 
V

Van T. Dinh

I guess you can think of Recordset as a Table in memory that you can
manipulate / update by code.

Check Access VB Help / you Access programming boo on Recordset. There
should be plenty of info. on this.
 
N

Niniel

All right, I will do that; thank you.

Van T. Dinh said:
I guess you can think of Recordset as a Table in memory that you can
manipulate / update by code.

Check Access VB Help / you Access programming boo on Recordset. There
should be plenty of info. on this.
 

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