OnExit Event Procedure for appending to a text field

I have a form with 9 fields.
   1           2            3                  4             5             6             7        8           9              10
Item ID  Descr1    Field3            Field4      Field 5     Field6        Qty    Rate    ExtPrice      ProdCat

The OnExit for the Item Id performs several DLookups to fill-in the Desc1, Rate, and Product Category fields.

I need an OnExit Event Procedure to override the value in Descr1 when the value of the Product Category field equals "2".
The value to be written into the field needs to be the values of Fields 3 thru 6 seperated with by a dash.

1       (IU-1")        (Plate 1/4")   (1/2" AS)      ( )       (Plate 1/4")    1        50.00    50.00             2
1G     (IU-1" Gas)  (Plate 1/4")   (1/2" AS)   (Argon)   (Plate 1/4")   1        50.00    50.00             2

The OnExit EP should override the (IU-1") and (IU-1" Gas) with
                                                                                          (Plate 1/4" - 1/2" AS - Plate 1/4") and
                                                                               (Plate 1/4" - 1/2" AS - Argon - Plate 1/4")
Notice the first replacement does not place a dash if Field 5 is null. That should be true for all fields 3 thru 6.

More urgent than difficult. I can write a macro to perform this function, but would rather have the code.

Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.


CurrentDb.Execute "Update YourTable Set Descr1 = Field3 & '/' & Field4 & '/' & Field5 & '/' & Field6 Where ProdCat = '2'"

Please, backup before trying it.
Hi bigwoodyg

If ProdCat = 2 then
 Descr1 = (Field3) & IIf(Not (IsNull(Field4)), "-") & Field4 & IIf(Not (IsNull(Field5)), "-") & Field5 & IIf(Not (IsNull(Field6)), "-") & Field6

End if

Good Luck!

bigwoodygAuthor Commented:

three issues with your solution, I can't get around.  
First, my Table Name is made up by two names =  "PO Detail".
I believe the bracket fix this issue.

Second, after replacing the Field1 with actual field names, and attempted to enter a record I receive the following error:
Too few parameters. Expected 2.

CurrentDb.Execute "Update [PO Detail] Set Descr1 = Mono1Type & '/' & Mono1Size & '/' & Mono1Color & '/' & Mono2Type & '/' & Mono2Size & '/' & Mono2Color Where ProdCat = '2'"

Third, I'm not sure if your solution handles the null value criteria.
bigwoodygAuthor Commented:

I can't compile your solution. Receiving this error.

Arguement not optional.

Cursor rests at the first IIf.

Here's the actual code.

Private Sub Lite2_ColorCoat_Exit(Cancel As Integer)

If Category = 2 Then
 Descr1 = (Mono1Type) & IIf(Not (IsNull(Mono1Size)), "-") & Mono1Size & IIf(Not (IsNull(Mono1Color)), "-") & Mono1Color & IIf(Not (IsNull(Mono2Type)), "-") & Mono2Type

End Sub

Private Sub Lite2_ColorCoat_Exit(Cancel As Integer)

If Category = 2 Then
 Descr1 = (Mono1Type) & IIf(Not (IsNull(Mono1Size)), "-","") & Mono1Size & IIf(Not (IsNull(Mono1Color)), "-","") & Mono1Color & IIf(Not (IsNull(Mono2Type)), "-","") & Mono2Type
End if

End Sub


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Access

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.