some help with code

Donorottie
01-27-2003, 10:38 AM
I'm working on getting my label to format the way I 'd like it to. The following chunk of code has a number of "If" clauses for my search any number of which could be true. So I set my display values to the variable sDisplayVal. What Im looking to do is set my label up to diplay the results of my search when certian values are true.

The format Im looking for is this:

Your Search Criteria:
Anchor: sDisplayVal
Population: sDisplayVal
etc...

Thanks for any help.

heres my code

If (Trim(txtTenants.Text) = "All tenants" And cboAnchorTenants.ItemData(cboAnchorTenants.ListIndex) = 0 And Trim(cboPopulation.Text) = "Any population range" And Trim(cboHouseHolds.Text) = "Any number of households" And Trim(cboIncome.Text) = "Any household income range" And Trim(cboCenterSize.Text) = "Any size" And cboRegion.ItemData(cboRegion.ListIndex) = 0 And cboLeasingMgr.ItemData(cboLeasingMgr.ListIndex) = 0 And Trim(cboCityState.Text) = "All cities and states") Then
sDisplayVal = "All Properties"

'MsgBox ("SELECT distinct centers.center_id, centers.center_path, states.state_path, centers.center_name, states.state_name, states.region_id, states.state_id FROM centers INNER JOIN states ON centers.state_id = states.state_id where center_flag=1 and state_name + center_name order by state_name, center_name")
Call SearchResults.dload("SELECT distinct centers.center_id, centers.center_path, states.state_path, centers.center_name, states.state_name, states.region_id, states.state_id FROM centers INNER JOIN states ON centers.state_id = states.state_id where center_flag=1 and state_name + center_name order by state_name, center_name")

Else

sSelectClause = BuildSelect()

'//////// ENTER THE TENANT NAME
If Trim(txtTenants.Text) <> "All tenants" Then
sJoinClause = BuildJoin("tenants")
sWhereClause = BuildWhere("tenants", txtTenants, 0)
sDisplayVal = BuildExp("tenants", txtTenants, 0)
blnAnd = True
Else
'/////// SELECT A TENANT NAME FROM THE LIST

If cboAnchorTenants.ItemData(cboAnchorTenants.ListIndex) <> 0 Then
sJoinClause = BuildJoin("tenants")
sWhereClause = BuildWhere("anchors", cboAnchorTenants.ItemData(cboAnchorTenants.ListIndex), 0)
sDisplayVal = BuildExp("anchors", cboAnchorTenants, 0)
blnAnd = True
Else
'/////// SELECT A POPULATION VALUE FROM THE LIST
If Trim(cboPopulation) <> "Any population range" Then
'splitVal(cboPopulation, &s_start, &s_end)
sJoinClause = BuildJoin("population")
sWhereClause = BuildWhere("population", cboPopulation, 0)
sDisplayVal = BuildExp("population", cboPopulation, 0)
blnAnd = True
Else
'/////// SELECT A HOUSEHOLD VALUE FROM THE LIST
If Trim(cboHouseHolds) <> "Any number of households" Then
'splitVal(cboHouseHolds, &s_start, &s_end)
sJoinClause = BuildJoin("households")
sWhereClause = BuildWhere("households", cboHouseHolds, 0)
sDisplayVal = BuildExp("hoseholds", cboHouseHolds, 0)
blnAnd = True
Else
'/////// SELECT A INCOME VALUE FROM THE LIST
If Trim(cboIncome) <> "Any household income range" Then
'splitVal(cboIncome, &s_start, &s_end)
sJoinClause = BuildJoin("income")
sWhereClause = BuildWhere("income", cboIncome, 0)
sDisplayVal = BuildExp("income", cboIncome, 0)
blnAnd = True
Else
'////// SELECT A CENTER SIZE FROM THE LIST
If Trim(cboCenterSize) <> "Any size" Then
'splitVal(cboCenterSize, &s_start, &s_end)
sWhereClause = BuildWhere("center_size", cboCenterSize, 0)
sDisplayVal = BuildExp("center_size", cboCenterSize, 0)
blnAnd = True
Else
'////// SELECT A REGION FROM THE LIST
If cboRegion.ItemData(cboRegion.ListIndex) <> 0 Then
sJoinClause = ") "
sWhereClause = BuildWhere("regions", cboRegion.ItemData(cboRegion.ListIndex), 0)
sDisplayVal = BuildExp("regions", cboRegion, 0)
blnAnd = True
Else
'/////// SELECT A LEASING MGR FROM THE LIST
If cboLeasingMgr.ItemData(cboLeasingMgr.ListIndex) <> 0 Then
sJoinClause = BuildJoin("reps")
sWhereClause = BuildWhere("reps", cboLeasingMgr.ItemData(cboLeasingMgr.ListIndex), 0)
sDisplayVal = BuildExp("reps", cboLeasingMgr, 0)
blnAnd = True
Else
'//////// SELECT A STATE FROM THE LIST
If Trim(cboCityState) <> "All cities and states" Then
'splitVal(cbocitystate, &s_start, &s_end)
sWhereClause = BuildWhere("state_id", cboCityState, 0)
sDisplayVal = BuildExp("state_id", cboCityState, 0)
blnAnd = True
Else
'/////// SELECT A CITY FROM THE LIST
If Trim(cboCityState) <> "All cities and states" Then
'splitVal(cbocitystate, &s_start, &s_end)
sWhereClause = BuildWhere("center_city_id", cboCityState, 0)
sDisplayVal = BuildExp("center_city_id", cboCityState, 0)
blnAnd = True
Else

End If
End If
End If
End If
End If
End If
End If
End If
End If
End If

'//////// GET RID OF THE LAST 'AND'
If (Len(sWhereClause) > 0) Then
sWhereClause = " where " & sWhereClause & " and center_flag=1 "
Else
sWhereClause = sWhereClause & " where center_flag=1 "
sDisplayVal = "All Properties"
blnAnd = True
End If


'put SQL statement in form1
Form1.Text1.Text = (sSelectClause & sJoinClause & sWhereClause & sOrderClause)
Form1.Visible = True


'///////// ORDER CLAUSE
sOrderClause = BuildOrder(sOrderClause)

'//////// PERFORM SEARCH FUNCTION CONNECT ALL CLAUSES
Call SearchResults.dload(sSelectClause & sJoinClause & sWhereClause & sOrderClause)

End If

SearchResults.lblTenantName = "Your Search Criteria: " & sDisplayVal

Machaira
01-27-2003, 10:55 AM
First, I don't believe you need all those Else statements.
Second, what exactly isn't working? What do the Build... functions do? What does sDisplayVal look like currently?
Third, you might want to learn to use the underscore "_" character to break long lines down.

Donorottie
01-27-2003, 11:32 AM
Ok, maybe some background might help. There are two forms, PropertySearch and SearchResults. The PropertySearch form has several combo boxes that the user can select from. The build functions are located in my module.

Once they made all there selections they hit search. Now the search function (or code below) looks at each possible selection. First, if all the values in the combo boxes are default, then a call is made to run a SQL statement.

If the values are not default then I have to build a SQL statement based on all the choices. Thats what the BUILD funtions are doing. At the very end of the search code string together all the build clauses and run the SQL statement.

(With me so far?)

The results are displayed on the SearchResults.frm in a flexgrid and a label. The flexgrid holds all the records from the Call SearchResults.dload statements and the label holds the records from the sDisplayVal statements. (Got it?)

All my records are showing up in my flex grid correctly so Im not worried about that. What I want to do is format or arrange how the sDisplay values look in the label.

(Are you with me still?)

If the all the combo boxes are set to default the label should show;

Your Search Criteria:
All Properties

or

Your Search Criteria:
Anchor: Some name
Population: Some number



It's does not it looks like this:

Your Search Criteria: All Properties
or
Your Search Criteria: Anchor: Some name
or
Your Search Criteria: Population: Some number.


I hope that helps explain.

N2DFire
01-27-2003, 12:32 PM
Using this one line as an example, try adding a vbCrLf to each DisplayVal statement.

I.e.
Change this
sDisplayVal = BuildExp("tenants", txtTenants, 0)
to this
sDisplayVal = BuildExp("tenants", txtTenants, 0) & vbCrLf

Donorottie
01-27-2003, 05:19 PM
N2Dfire

I tried your suggestion with out any results. I then tried

SearchResults.lblTenantName = "Your Search Criteria: " & vbCrLf & sDisplayVal

and it works fine now, thanks for the tip

Donorottie
01-27-2003, 07:07 PM
Machaira,

YOu indicated earlier that I might not need all the If's. How else would you do this?

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum