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

Using a string as a comparsion value. 3

Status
Not open for further replies.

SteveCarrier

Programmer
Aug 6, 2002
34
CA
I have a table with two columns, one that holds a variable name and the other that holds a reference to it's related field. For example the first record might be:
varName = strCategory
varValue = Form_frmTest.pgCategory

and the next:
varName = strTitle
varValue = Form_frmTest.pgTitle

I have a function which uses the varName to check which field to access. For example, if strTitle is found my function GetVariable will return:

GetVariable = varValue

This works great other than the fact that it returns:

GetVariable = &quot;Form_frmTest.pgTitle&quot; <----- with the quotation marks. I would like it to return the actual value of Form_frmTest.pgTitle.

Any Ideas? (I know it's confusing)

Thanks in advance.
Steve Carrier
 
I think you are going to have to do some parsing of the value being returned by your function. It is treating it as a piece of text--not as a form name followed by a field name on the form. My suggestion:

FirstPeriod=instr(GetVariable,&quot;.&quot;,1)
FormName=left(GetVariable, FirstPeriod-1)
FieldName=mid(GetVariable, FirstPeriod+1)

GetVariable=FormName.FieldName

Frank kegley
fkegley@hotmail.com
 
varValue = Forms(&quot;FormName&quot;)(&quot;TextBoxName&quot;)

or

varValue = Forms![FormName]![TextBoxName]

will take the value of the text box.


From what you've posted, I think you'll have:
varValue = Forms(&quot;Form_frmTest&quot;)(&quot;pgCategory&quot;)

HTH

Dan
[smile]
 
Thanks for your prompt reply guys!

Everything was great and I get the value of the form and the field stored in two seperate variables, but the last statement is not working properly.

strTemp = FormName.FieldName gives me an invalid qualifier error.

strTemp = Forms![FormName]![FieldName] gives me a bunch of errors also.

Hopefully I am missing something simple.

Thanks
 
Just to add I really just need the field name since the form with the records is always Form_frmTest

So I try this with my strFieldName variable:

strValue = Form_frmTest.[strFieldName] but I get this error message:

Microsoft can't find the field &quot;|&quot; as found in your expression.

Maybe my syntax is off.

Thanks

Steve
 

FYI

formname = &quot;form1&quot;
textboxname = &quot;text0&quot;


'referencing
function HelpStuff()

dim strField as string
dim strForm as string

strField = &quot;text0&quot;
strForm = &quot;form1&quot;

MsgBox Forms!form1(&quot;text0&quot;).Value
MsgBox Forms!form1(strField).Value
MsgBox Forms(strForm)(strField).value

End Function


hope this help your problem

'strValue = Form_frmTest.[strFieldName] '
as you entered is looking for a field named &quot;strfieldname&quot; on the form and not the contents of that variable

UrbaneRove

 
Brilliant Stuff everyone. All the posts helped me a ton. Thanks again!

Steve
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top