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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How can i insert the output into a 3

Status
Not open for further replies.

Beresford

Technical User
Aug 16, 2001
2
GB
How can i insert the output into a field, which was generated by the following expression...

=[MainCat1] & [SubCat1] & "," & [MainCat2]+[SubCat2] & "," & [MainCat3]+[SubCat3] & "," & [MainCat4]+[SubCat4] & "," & [MainCat5]+[SubCat5] & "," & [MainCat6]+[SubCat6]

into a table.

please help

by the way [MainCat] is referring to combo boxes
 
The code would be...

Docmd.RunSQL "UPDATE TableName SET FieldName = '" & Me!FieldName & "'"

TableName = The name of the table you wish to update.
FieldName = The field in the table you wish to update.
Me!FieldName = the calculated field.

I put the tick marks (apostrophe) because it looks like this field is alpha numeric. If not, remove them. Where you put the code would depend on which event triggers the concantenation of your text. ljprodev@yahoo.com
ProDev, MS Access Applications B-)
 
Assuming the expression is calculated on the Form where the [MainCatN] comboboxes are, you apprar to be assiginb the expression to a text type of control (as it's record source?). While there are various approaches to this, a simple one is to do the assignment in code. In each of the [MainCatN] comboboxes' after update event, call a procedure. In that procedure, set the control VALUE to the expression. Bind the control source tot he field in the table.

MichaelRed
mred@att.net

There is never time to do it right but there is always time to do it over
 
Cheers Mike

Was unsure at first but worked a treat...

catergorycode, is bound to the destination column in the table the rest of the code went as follows...


Private Sub SubCat1_AfterUpdate()

Me.categorycode.Value = [MainCat1] & [SubCat1]

End Sub

Private Sub SubCat2_AfterUpdate()

Me.categorycode.Value = Me.categorycode.Value & "," & [MainCat2] + [SubCat2]

End Sub
Private Sub SubCat3_AfterUpdate()

Me.categorycode.Value = Me.categorycode.Value & "," & [MainCat3] + [SubCat3]

End Sub
 
Close, but is has a few potential flaws.

If you (or your user) udates the objects "Out of sequence", you can easily get the wrong answer. try it like ... :


Private Sub SubCat1_AfterUpdate()

Call CatCodeUpdate

End Sub

Private Sub SubCat2_AfterUpdate()

Call CatCodeUpdate

End Sub

Private Sub SubCat3_AfterUpdate()

Call CatCodeUpdate

End Sub


Private Function CatCodeUpdate()

Me.categorycode = [MainCat1] & [SubCat1] & "," & _
[MainCat2] & [SubCat2] & "," & _
[MainCat3] & [SubCat3]

End Function


MichaelRed
mred@att.net

There is never time to do it right but there is always time to do it over
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top