Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations John Tel on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Update table with values from UNBOUND text box

Status
Not open for further replies.

RiderJon

Programmer
Aug 26, 2002
190
FR
Hi:

How do you update a table with values from unbound box.

I have a combo-box with values "app" and "rev".
Next to it is a text box.

If the user selects "app", I want the value in the textbox to update "App Memo" column in tblInfo.

Else, the "Rev Memo" field will be updated with values from the text box.

Thanx a bunch.



RiderJon
"I might have created ctrl+alt+del,
But Bill made it famous" - Dr. Dave
 
Are you updating this value for all records. If you you will want to put code in the afterupdate event of the combo box or the click event of a button if you will let them change their minds.

I would write an update query that calls the field on your form that will update the correct field. For instance the the sql for that query will be

UPDATE tblInfo SET [tblInfo].[App Memo] = Forms!<FormName>!<text box name>.value;

Since this form will be open when you call it should work.

The event will call this query to be run. Actually it will have to check for which value was chosen and then run different queries in different cases.
 
Hi

As Hmadyson said, it is unclear which record you want to update.

I am assuming the following:

You have other 'bound' controls on the form which show which record you are looking at and you want to update that record only with your selection.

You will supply the text field value and then select the item in the combo box (and then, i suggest click a button to save the info to the App Memo field for the current record).

I have tested this code and it works, but there is no error checking.

Code Start
********
Private Sub cmdSaveText_Click()
Call SaveText(cboType.Value)
End Sub

Public Sub SaveText(SavedText As String)
Dim rsMyTable As Recordset

Set rsMyTable = CurrentDb.OpenRecordset(&quot;MyTable&quot;)

With rsMyTable
.Edit
If SavedText = &quot;app&quot; Then
![App Memo] = txtType.Value
Else
![Rev Memo] = txtType.Value
End If
.Update
End With

rsMyTable.Close
Set rsMyTable = Nothing
End Sub

********
It works like this...

1. Select the combo box item (app or rev)
2. Enter any text u want in the text box
3. Hit a button called cmdSaveText

I dont know how much VBA exp. u have, but I am assuming u have some.

NOTE: The above sample code does NOT find the relevant record, that will have to be programmed in. This only updates the first record in MyTable.

If you want further help, just ask.

HTH
 
Thanx for the reply Hmadyson and HTH.

Sorry for not being more clearer. I got it to work by putting the code in the &quot;onExit&quot; event.






RiderJon
&quot;I might have created ctrl+alt+del,
But Bill made it famous&quot; - Dr. Dave
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top