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

Help with IF/THEN/ELSE statements 2

Status
Not open for further replies.

Accel45

Technical User
Jul 7, 2004
83
US
I am using the code below to replace character strings that I create. Upon clicking a command button the character string is replaced by data from the form. This does what I need it to do.
My problem is that I have forty (40) fields on the form where I use the character strings and using this method I have to create an IF/THEN/ELSE for each of the 40 fields. (Words1 to Words40) Further when I add a new character string I have to add it to each of the 40 IF/THEN/ELSE statements.
What I am looking for is a way to look for the character strings in all 40 Words fields without using 40 IF/THEN/ELSE statements. Any help would be appreciated.

If IsNull(Words1) Then
Else
Me.Words1 = sReplace(Words1, "(*XPX*)", Nz(RLicExp, "(*XPX*)"))
Me.Words1 = sReplace(Words1, "ASSTAG", Nz(PName, "ASSTAG"))
Me.Words1 = sReplace(Words1, "RNP", Nz(RName, "RNP"))
Me.Words1 = sReplace(Words1, "ATTY", Nz(AName, "ATTY"))
Me.Words1 = sReplace(Words1, "RSTREET", Nz(RStreet, "RSTREET"))
Me.Words1 = sReplace(Words1, "TCY", Nz(RCity, "TCY"))
Me.Words1 = sReplace(Words1, "YX", Nz(RState, "YX"))
Me.Words1 = sReplace(Words1, "ZP", Nz(RZip, "ZP"))
Me.Words1 = sReplace(Words1, "(Last Name)", Nz(txtRLName, "(Last Name)"))
Me.Words1 = sReplace(Words1, "(*Month*)", Nz(txtMonth, "(*Month*)"))
Me.Words1 = sReplace(Words1, "(*Year*)", Nz(txtYear, "(*Year*)"))
Me.Words1 = sReplace(Words1, "(*Full*)", Nz(txtFullDate, "(*Full*)"))
Me.Words1 = sReplace(Words1, "(*LicType*)", Nz(txtRLicType, "(*LicType*)"))
Me.Words1 = sReplace(Words1, "(*Z3Z*)", Nz([txtNextPH], "(*Z3Z*)"))
Me.Words1 = sReplace(Words1, "(*B*D*)", Nz(txtBoardSign, "(*B*D*)"))
End If

Thanks
Accel45
 



Hi,

How about...
Code:
for i = 1 to 40
  Me.textbox("Words" & i) = sReplace(Me.textbox("Words" & i), "(*XPX*)", Nz(RLicExp, "(*XPX*)"))
'......
next



Skip,

[glasses] [red][/red]
[tongue]
 
SkipVought,

Thank you for your help.

I gave this a try (probably incorrectly) and I get the following error message:

"Compile error:
Method or data member not found"

The error is on Me.textbox
 
And this ?
Me.Controls("Words" & i) = sReplace(Me.Controls("Words" & i), "(*XPX*)", Nz(RLicExp, "(*XPX*)"))

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
OK that worked. After I put text in each of the controls. I
Was getting an error "Invalid Use of Null" on the Me.Controls where the control is empty.

Where do I write the "If IsNull(Words1) Then" to have it check each of the controls.
 
Me.Controls("Words" & i) = sReplace(Me.Controls("Words" & i) & "", "(*XPX*)", Nz(RLicExp, "(*XPX*)"))

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Thank you both for your help, that really cleaned up my code.

Accel45
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top