How to stop vba running if the text box has text in

monplankton

Registered User.
Local time
Today, 01:40
Joined
Sep 14, 2011
Messages
83
currently using a2003 and I have vba updating a text box with a paragraph of text after a check box has been updated. What I don't want it to do is update the text box if text already exsist but put a message box saying delte text before update, here is my code.


Me![Investigation Results] = Me![Investigation Results] & "During" & " " & [Combo26] & " " & "trial build the following concern/s were/was found." & vbCrLf & " 1." & vbCrLf & " 2. -List all items with specs and actuals where possible" & vbCrLf & " 3." & vbCrLf

any help much appreciated
 
Code:
If Me.[Investigation Results] & "" = "" Then
    Me![Investigation Results] = Me![Investigation Results] & "During" & " " & [Combo26] & " " & "trial build the following concern/s were/was found." & vbCrLf & " 1." & vbCrLf & " 2. -List all items with specs and actuals where possible" & vbCrLf & " 3." & vbCrLf
Else
    If MsgBox("Do you want to replace the results?", vbYesNo) = vbYes Then
        Me![Investigation Results] = Me![Investigation Results] & "During" & " " & [Combo26] & " " & "trial build the following concern/s were/was found." & vbCrLf & " 1." & vbCrLf & " 2. -List all items with specs and actuals where possible" & vbCrLf & " 3." & vbCrLf
    End If
End If
 
Thanks for that works a treat
 
Pat,

Thanks again for the code. I have another question. Could the could work on the tick box being true or false? What I'm finding is if somebody ticks it by mistake, then un ticks it and says no to message it duplicates the sentance.
 
Put the code in the Form's BeforeUpdate event. That way it doesn't matter how many times they change during th editing session. You may need to use the control's .OldValue property to compare the original value with the new value. If they are the same, the field wasn't changed, if they are different it was. You will need to check specifically for null on either side since somevalue compared to null will always be false and null compared to null will also be false.
 

Users who are viewing this thread

Back
Top Bottom