This doesn't care whether Yes or No

  • Thread starter Thread starter Mary Hartman
  • Start date Start date
M

Mary Hartman

I have written the following sub-routine to fill in 2 fields if a
check box is checked. However, the routine doesn't seem to care if
the check box (products_image_1_use) is checked or not, it fills the
fields when I click on check box and empties it when I click on the
check box no matter the value of the check box. I want the field
filled only when the check box is checked.

It's gotta be something stupid. What have I done wrong?
______

Private Sub products_image_1_use_Click()

Dim products_image_name_sm_1_temp As String
Dim products_image_name_lg_1_temp As String

If Me![products_image_1_use] = Yes Then
products_image_name_sm_1_temp = Me![products_model]
products_image_name_sm_1_temp = products_image_name_sm_1_temp &
"bw.jpg"
Me![products_image_sm_1] = products_image_name_sm_1_temp

products_image_name_xl_1_temp = Me![products_model]
products_image_name_xl_1_temp = products_image_name_xl_1_temp &
"b.jpg"
Me![products_image_xl_1] = products_image_name_xl_1_temp
Else
Me![products_image_sm_1] = vbNullString
Me![products_image_xl_1] = vbNullString
End If

End Sub
 
On Sat, 09 Dec 2006 21:56:16 -0500, Mary Hartman

I knew it was something stupid. I changed yes to true and all is
well.

Thanks for looking and have a great day!!!!!
 
Suggestions:

1. Use the AfterUpdate event.

2. Test if the value is True. (Yes is not defined in VBA.)

3. Assign the value Null (the value of a field without data), not
vbNullString (which is a zero-length string.)

4. Test if products_model is null.

5. Add Option Explicit to the top of your module so it catches bad names.

Private Sub products_image_1_use_AfterUpdate()
If (Me.[products_image_1_use] = True) And Not
IsNull(Me.[products_model]) Then
Me.[products_image_sm_1] = Me.[products_model] & "bw.jpg"
Me.[products_image_xl_1] = Me.[products_model] & "b.jpg"
Else
Me.[products_image_sm_1] = Null
Me.[products_image_xl_1] = Null
End If
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

Back
Top