By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
426,045 Members | 1,760 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 426,045 IT Pros & Developers. It's quick & easy.

Check fields from hidden form and change data on original form

P: 31
Ok, so i looked up the information that i needed, but now I see that what i was trying to do was really made for a SQL statement.

Here is what happens. I open a form (hidden) with 20+ fields on it. Any of the fields may have a term on it. (MPI or LPI) <-- text obviously. If they exist in any of the fields, then i need to make a label visible on the form that is actually going to be used. Then the hidden form closes.

The code i tried unsuccesfully to use looked like this

Expand|Select|Wrap|Line Numbers
  2. if [op1] like (*MPI*) or if [op2] like (*MPI*) then
  3. forms!otherform.label = true
  4. end if
  5. if [op1] like (*LPI*) or if [op2] like (*LPI*) then
  6. forms!otherform.label2 = true
  7. end if
the only time it worked is when i made it look like this
Expand|Select|Wrap|Line Numbers
  2. if [op1] like (*) then
But of course then it doesnt matter what is in the field.
Is there a way to accomplish what i am doing. I am sure that there is a complicated method of doing it..... I am also quite sure that i am not doing it very efficiently, but I try to actually learn how to read the code that i use, so that i will learn it. So the easier the better :), but if complicated is the only way, then complicated it is. Thanks in advance.
Jan 30 '09 #1
Share this Question
Share on Google+
1 Reply

Expert Mod 2.5K+
P: 2,545
Hi. If you want to compare string control values to string literal text values you need to enclose the string literals in double quotes:

Expand|Select|Wrap|Line Numbers
  1. if ([op1] like "*LPI*") OR ([op1] like "*DPI*") then
  2.    ...
  3. End If
(see our insight article Quotes and Double Quotes - Where and When to Use Them for more on this.)

The use of the wildcard character "*" before and after the pattern allows you to find any occurrence of the given pattern within any other characters in the string - for example "Printer; DPI". You would not need the wildcards before and after the pattern if it is never preceded by or followed by other characters in your string, but you don't say whether or not this would apply in your case.

With 20 controls in your hidden form you are likely to end up with a lot of IF statements. There are more efficient ways to process these, depending on how you name the controls and what you are doing with them. One way is to ensure that they are named, say, Op1, Op2, Op3..Op20. These can then be processed in a loop, like this:

Expand|Select|Wrap|Line Numbers
  1. Dim strCtrlName as String
  2. Dim intCtrlNo as Integer
  3. Dim varCtrlValue as Variant
  4. For intCtrlNo = 1 to 20
  5.     strCtrlName = "Op" & intCtrlNo ' this just concatenates the control name with the number to form Op1, Op2 etc
  6.     varCtrlValue =  me.controls(strCtrlName)
  7.     if not IsNull(varCtrlValue) then
  8.        if (varCtrlValue like "*DPI*) or (varCtrlValue like "*LPI*) then
  9.          <do stuff>
  10.        end if
  11.     end if 
  12. Next intCtrlNo
There are many possibilities - I am sure there are other approaches that would work just as well that others could think of.

Jan 31 '09 #2

Post your reply

Sign in to post your reply or Sign up for a free account.