Function ftestConditions

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have a table that I've imported into Access and need to base a conditional
format on the following

Public Function fTestConditions(strWorkstation, strDescription)
If strWorkstation = ([30,071-C-02_A]) Then
fTestConditions = True

My "strWorkstation" text is "30,071-C-02 A" and I'm wondering what the rules
are regarding using commas and dashes and numbers and text as I'm not able to
get the results I need. I pulled this table in and unfortunately the
workstation numbering (30,071-C-02 A) must remain as is.

Thanks.
 
Michelle said:
I have a table that I've imported into Access and need to base a conditional
format on the following

Public Function fTestConditions(strWorkstation, strDescription)
If strWorkstation = ([30,071-C-02_A]) Then
fTestConditions = True

My "strWorkstation" text is "30,071-C-02 A" and I'm wondering what the rules
are regarding using commas and dashes and numbers and text as I'm not able to
get the results I need. I pulled this table in and unfortunately the
workstation numbering (30,071-C-02 A) must remain as is.


Literal text strings need to be in quotes:

If strWorkstation = "30,071-C-02_A" Then
 
Marshall, I put this in my code but it still isn't working. I do have my
conditional formatting for the text box (workstation) set as
fTestConditions([Workstation]) and then have the font set as Bold Red and the
fill as yellow. If I put in the words "test" and it works (the highlight &
font color) but not sure why the "literal" string doesn't?
Thanks.

Public Function fTestConditions(strWorkStation)

If strWorkStation = "30,071-C-02_A" Then
fTestConditions = True

End If
End Function

Marshall Barton said:
Michelle said:
I have a table that I've imported into Access and need to base a conditional
format on the following

Public Function fTestConditions(strWorkstation, strDescription)
If strWorkstation = ([30,071-C-02_A]) Then
fTestConditions = True

My "strWorkstation" text is "30,071-C-02 A" and I'm wondering what the rules
are regarding using commas and dashes and numbers and text as I'm not able to
get the results I need. I pulled this table in and unfortunately the
workstation numbering (30,071-C-02 A) must remain as is.


Literal text strings need to be in quotes:

If strWorkstation = "30,071-C-02_A" Then
 
I don't see anything obviously wrong with that code.

Is strWorkstation a field in the form's record source
table/query, a text box control on the form, or a VBA
variable? If it's a VBA variable, where is it defined?

What view is the form using, Single, continuous or
Datasheet?

Does the field in the table really have that text string?
Your original post had it with and without [ ] and ( )
around it.
--
Marsh
MVP [MS Access]

Marshall, I put this in my code but it still isn't working. I do have my
conditional formatting for the text box (workstation) set as
fTestConditions([Workstation]) and then have the font set as Bold Red and the
fill as yellow. If I put in the words "test" and it works (the highlight &
font color) but not sure why the "literal" string doesn't?
Thanks.

Public Function fTestConditions(strWorkStation)

If strWorkStation = "30,071-C-02_A" Then
fTestConditions = True

End If
End Function

Marshall Barton said:
Michelle said:
I have a table that I've imported into Access and need to base a conditional
format on the following

Public Function fTestConditions(strWorkstation, strDescription)
If strWorkstation = ([30,071-C-02_A]) Then
fTestConditions = True

My "strWorkstation" text is "30,071-C-02 A" and I'm wondering what the rules
are regarding using commas and dashes and numbers and text as I'm not able to
get the results I need. I pulled this table in and unfortunately the
workstation numbering (30,071-C-02 A) must remain as is.


Literal text strings need to be in quotes:

If strWorkstation = "30,071-C-02_A" Then
 
I would try one minor modification.

Public Function fTestConditions(strWorkStation) as Boolean

If strWorkStation = "30,071-C-02_A" Then
fTestConditions = True

End If
End Function

Or

Public Function fTestConditions(strWorkStation)

If strWorkStation = "30,071-C-02_A" Then
fTestConditions = True
else
fTestCondtions = False
End If

End Function




'====================================================
John Spencer
Access MVP 2002-2005, 2007
Center for Health Program Development and Management
University of Maryland Baltimore County
'====================================================

Marshall, I put this in my code but it still isn't working. I do have my
conditional formatting for the text box (workstation) set as
fTestConditions([Workstation]) and then have the font set as Bold Red and the
fill as yellow. If I put in the words "test" and it works (the highlight &
font color) but not sure why the "literal" string doesn't?
Thanks.

Public Function fTestConditions(strWorkStation)

If strWorkStation = "30,071-C-02_A" Then
fTestConditions = True

End If
End Function

Marshall Barton said:
Michelle said:
I have a table that I've imported into Access and need to base a conditional
format on the following

Public Function fTestConditions(strWorkstation, strDescription)
If strWorkstation = ([30,071-C-02_A]) Then
fTestConditions = True

My "strWorkstation" text is "30,071-C-02 A" and I'm wondering what the rules
are regarding using commas and dashes and numbers and text as I'm not able to
get the results I need. I pulled this table in and unfortunately the
workstation numbering (30,071-C-02 A) must remain as is.

Literal text strings need to be in quotes:

If strWorkstation = "30,071-C-02_A" Then
 
Marshall, the strWorkstation is a combo box and the row source type is a
table/query. The Row Source is a query called "Work Instruction Numbers"
(the query is from a table I imported and the category field for Workstation
is set as a "text" field). It's a single form and the text string in my
field is "30,071-C-02 A". There are no quotes around it.

My conditional formatting is "fTestConditions([WorkStation])" (without the
quotes). Like I said, if I put the word "test" in my table it works, so I'm
thinking it has to do with the way my string is?? Thanks.



Marshall Barton said:
I don't see anything obviously wrong with that code.

Is strWorkstation a field in the form's record source
table/query, a text box control on the form, or a VBA
variable? If it's a VBA variable, where is it defined?

What view is the form using, Single, continuous or
Datasheet?

Does the field in the table really have that text string?
Your original post had it with and without [ ] and ( )
around it.
--
Marsh
MVP [MS Access]

Marshall, I put this in my code but it still isn't working. I do have my
conditional formatting for the text box (workstation) set as
fTestConditions([Workstation]) and then have the font set as Bold Red and the
fill as yellow. If I put in the words "test" and it works (the highlight &
font color) but not sure why the "literal" string doesn't?
Thanks.

Public Function fTestConditions(strWorkStation)

If strWorkStation = "30,071-C-02_A" Then
fTestConditions = True

End If
End Function

Marshall Barton said:
Michelle wrote:

I have a table that I've imported into Access and need to base a conditional
format on the following

Public Function fTestConditions(strWorkstation, strDescription)
If strWorkstation = ([30,071-C-02_A]) Then
fTestConditions = True

My "strWorkstation" text is "30,071-C-02 A" and I'm wondering what the rules
are regarding using commas and dashes and numbers and text as I'm not able to
get the results I need. I pulled this table in and unfortunately the
workstation numbering (30,071-C-02 A) must remain as is.


Literal text strings need to be in quotes:

If strWorkstation = "30,071-C-02_A" Then
 
John, I tried both of these but they didn't work. Thanks for your help.

John Spencer said:
I would try one minor modification.

Public Function fTestConditions(strWorkStation) as Boolean

If strWorkStation = "30,071-C-02_A" Then
fTestConditions = True

End If
End Function

Or

Public Function fTestConditions(strWorkStation)

If strWorkStation = "30,071-C-02_A" Then
fTestConditions = True
else
fTestCondtions = False
End If

End Function




'====================================================
John Spencer
Access MVP 2002-2005, 2007
Center for Health Program Development and Management
University of Maryland Baltimore County
'====================================================

Marshall, I put this in my code but it still isn't working. I do have my
conditional formatting for the text box (workstation) set as
fTestConditions([Workstation]) and then have the font set as Bold Red and the
fill as yellow. If I put in the words "test" and it works (the highlight &
font color) but not sure why the "literal" string doesn't?
Thanks.

Public Function fTestConditions(strWorkStation)

If strWorkStation = "30,071-C-02_A" Then
fTestConditions = True

End If
End Function

Marshall Barton said:
Michelle wrote:

I have a table that I've imported into Access and need to base a conditional
format on the following

Public Function fTestConditions(strWorkstation, strDescription)
If strWorkstation = ([30,071-C-02_A]) Then
fTestConditions = True

My "strWorkstation" text is "30,071-C-02 A" and I'm wondering what the rules
are regarding using commas and dashes and numbers and text as I'm not able to
get the results I need. I pulled this table in and unfortunately the
workstation numbering (30,071-C-02 A) must remain as is.

Literal text strings need to be in quotes:

If strWorkstation = "30,071-C-02_A" Then
 
I got it to work! I had the control source of "Description" set to
=Workstation.Column(1) so that when someone clicks on the "workstation" the
"description" would automatically pop up. I then changed from function to...

If strWorkStation = "30,071-C-02_A" Then
fTestConditions = True
ElseIf strWorkStation = "Station #2 - Hot Plate Weld GMT 968
Applique-Nissan line" Then
fTestConditions = True

so the conditional formatting worked.

Thanks to you both for your help. If there's a better way to do this, I'm
up for suggestions but right now I'm just happy it works.
 
Michelle said:
I got it to work! I had the control source of "Description" set to
=Workstation.Column(1) so that when someone clicks on the "workstation" the
"description" would automatically pop up. I then changed from function to...

If strWorkStation = "30,071-C-02_A" Then
fTestConditions = True
ElseIf strWorkStation = "Station #2 - Hot Plate Weld GMT 968
Applique-Nissan line" Then
fTestConditions = True

so the conditional formatting worked.

Thanks to you both for your help. If there's a better way to do this, I'm
up for suggestions but right now I'm just happy it works.


I don't like that function because it imbeds data from a
table in its code. Is there a way you can add a field in
the combo box's row source table to contain a format code
value? If there were such a field with a value, e.g 1, for
the workstations you want to highlight, then the function
could be simplified to just the one line:

Public Function fTestConditions(strWorkStation)
fTestConditions = Me.strWorkStation.Column(x)
End Function

Then, if you ever need to change which worstations should be
highlighted, you would only need to edit a record in the
table.
 
Should I add a column to my table (Critical Station) and put a "yes" in each
critical station row. Would my code be:

Public Function fTestConditions(strWorkStation)
fTestConditions = Me.Workstation.Column(Critical_Station) = yes
End Function

Right now I have a combo box for "Workstation" and "Description". Would I
also need a field on the form for "Critical Station". Is that where I would
put the format code in the row source? I'm confused. Thanks.
 
I got it to work. I had the wrong str listed. Duh...Anyway, I was wondering
if you can open a form based on a fTestCondition. Here is my code:

Public Function fTestConditions(strCriticalStation)
fTestConditions = Me.CriticalStation = "Yes"

I would like to open "Critical Station Form" (it's a pop up form)
automatically when my critical station is "yes".

Thanks again for all your help - (you have no idea how much you have helped
me).
 
I don't know what tables you are using for what purpose, but
it will be related to what you are using for the combo box's
Row Source.

You said that you have a Critical Station table, but other
things you've said imply that the combo box has other
workstations, so I think the combo box must use another
table. Remember that the heart of a database is its tables,
so the solution to most every problem starts with an
examination of the involved tables.

This is not a tricky situation, it just needs a clear
description of the data that's used for the combo box.
 
Michelle said:
I got it to work. I had the wrong str listed. Duh...Anyway, I was wondering
if you can open a form based on a fTestCondition. Here is my code:

Public Function fTestConditions(strCriticalStation)
fTestConditions = Me.CriticalStation = "Yes"

I would like to open "Critical Station Form" (it's a pop up form)
automatically when my critical station is "yes".

Thanks again for all your help - (you have no idea how much you have helped
me).


I think all you need is:

Public Function fTestConditions(strCriticalStation)
fTestConditions = Me.CriticalStation = "Yes"
If fTestConditions Then
DoCmd.OpenForm "Critical Station Form"
End If
 
Marshall, I'm still trying to get my "Critical Station Form" to open based on
my test conditions. I pasted the code you gave me but it didn't work. My
text box didn't turn to yellow (like it should if fTestConditions are True)
either. Thanks for your help.

Public Function fTestConditions(strCriticalStation)
fTestConditions = Me.CriticalStation = "Yes"
If fTestConditions Then
DoCmd.OpenForm "Critical Station Form"
End If
 
"it didn't work" really doesn't provide enough information
to work with here.

Did it generate an error of some kind? Or, did nothing at
all happen?

Did you change something else that is interfering with what
was accomplished earlier?

Maybe Conditional Formatting can not deal with a form being
opened while it is trying to evaluate a condition. Since
the form is in Single view, let's try a different approach
that avoids CF. Use the form's Current event with code to
set the text box properties and remove the CF condition for
the text box:

If Me.CriticalStation = "Yes" Then
Me.thetextbox.BackColor = vbYellow
. . .
DoCmd.OpenForm "Critical Station Form"
End If
 
Back
Top