Vba code question

Jon123

Registered User.
Local time
Today, 11:55
Joined
Aug 29, 2003
Messages
668
I have a code question. I have a checklist form that user initial steps as they complete them. Once a step is complete it gets lock so someone else can't go in and make changes. Because rework is sometimes needed I added a command button that unlocks certain steps. So I have this code on a command button

If Not IsNull (me.step5) Then
Me.[step5] = "1" & "- " & Me.[step5]
Else
End If

And this repeats for every step that gets reset.
Now what it does is if someone has initialed step 5 this code would put 1- XX infront of the initials. Which works fine. The question I have is is there A way to ignor it if it's already set to 1- XX ? Right now I get 1- 1- Xx if I run it twice?

Jon
 
Try this untested code:
Code:
if Me.[step5] <> "1- XX" then
     Me.[step5] = "1" & "- " & Me.[step5]
end if
This code should only perform the modification to "step5" if it does not already have the "1-XX" value.
 
Sorry I need to change it if it is not null so if step 5 has initials JD and my code runs it puts the 1- JD in the field if it runs again it puts 1- 1- JD in the field. So if it's null it put nothing. So I know I can put another If statement but I was hoping for something simpler
 
Ok. Try this code:
Code:
if not IsNull(me.step5) or me.step5 <> "" then
     Me.step5 = "1" & "- " & me.step5
end if

I have included the "Not Is Null" and the not null string (<> "") so it will trap either of the possible values.

Hope this helps.
 
Code:
if not IsNull(me.step5) or me.step5 <> "" then

A common more compact alternative which achieves the same test is:

If Len(Nz(Me.Step5,"")) > 0 Then
 
Wait a sec. I need to catch the field if its not null and if its already 1- something. So let say
step5 currently = JD and the code runs it will make step 5 = 1- JD and if it runs a second time then step5 will = 1- 1- JD and if it runs a 3rd etc etc etc every time it runs it will put a 1- in front of whatever is in step5. What I want is if step5 is Null then it stays null if step5 is 1- JD and it runs I would like it to stay 1- JD and not add the second 1- to the already 1-
 
if not IsNull(me.step5) and left(me.step5,2) <> "1-" then

??
 
Awesome works, could you be so kind and explain the and left to me?

jim
 
Suggest you try F1 for a detailed explenation
 

Users who are viewing this thread

Back
Top Bottom