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

using Conbo boxs and Radio button - radio group for a selection

Status
Not open for further replies.

EH

Programmer
Sep 17, 2001
9
AU
Hi there,

We are trying to use a radio group component as a dynamically created object that is to enable us to make a select of one from three buttons for say 50 people. We are having trouble selecting all buttons, making different selection combination using the combo boxes and then posting the information to an access table. See details below.

1. Situation
1.1. We have sales representatives (SR) (50-60 SR’s) that are required to complete a campaign.
1.2. There are 18 campaigns (Cmp) for the year. There are 10 groups of SR’s.
1.3. We have used combo boxes that will 1. Select the year, 2. Select the Cmp (1 to 18). 3. Select the group (1-10). One the selections are made a button is pressed.
1.4. This brings up on the form, a dynamically created object (radio boxes), showing 3 buttons (button 1 – completed, button 2 – missed button 3 – suspended), for each of the SR’s in that group.
1.5. Only one of the 3 button can be chosen. Once selected press a save button. This information is registered in a database.

2. Problem
We have been able to create the above but cannot do the following:
2.1. Only press one of the three buttons (not be able to select all three buttons).

2.2. If there are 50 SR’s how do we do a select all for say, the completed button (or missed button etc), or do a deselect all. (we can only press one button at a time).

2.3. Once selections have been made, how is this posted this into an access table, as an integer.
2.3.1. We would like the button selection, to show as an integer (say one) to allow for calculations to be perofrmed.
2.3.2. A typical calculation is e.g. So in one year (18 Cmp’s) a SR will have completed 10, missed 4, suspended 4 (total 18).
2.3.3. The calculation ill be carried out by an sql query.

2.4. How can you refresh and choose another combo box combination, to then show a different group of SR’s.

3. We have used the Radio group component as a dynamically created object.

4. A copy of the code is attached that reflects point 1.
procedure TfrmCampSrep.FormActivate(Sender: TObject);
var
i: integer;
begin
DmAvon1.tblTA.close;
DmAvon1.tblTA.open;
DmAvon1.tblTA.First;
ComboBox1.Items.clear;
while not DmAvon1.tblTA.Eof do
begin
combobox1.Items.Add(inttostr(dmAvon1.tblTa.fieldbyname('TmArId').asinteger));
dmAvon1.tblTA.Next;
end;
DmAvon1.tblTA.close;

for i := 1 to 18 do
begin
ComboBox3.Items.Add(inttostr(i));
end;
ComboBox3.ItemIndex := -1;

DmAvon1.tblCamp.close;
DmAvon1.tblCamp.open;
DmAvon1.tblCamp.First;
ComboBox2.Items.clear;
if dmAvon1.tblCamp.fieldvalues['CmpYr'] = NULL then
begin
dmAvon1.tblCamp.Close;
showmessage('There is no data to show'#13+
'First establish some campaigns in Campaign Setup Screen.');
exit;
end
else
begin
tempyear := dmAvon1.tblCamp.fieldvalues['CmpYr'];
ComboBox2.Items.add(inttostr(tempyear));
while not dmAvon1.tblCamp.Eof do
begin
if dmAvon1.tblCamp.fieldvalues['CmpYr'] <> tempyear then
begin
ComboBox2.Items.add(dmAvon1.tblCamp.fieldvalues['CmpYr']);
tempyear := dmAvon1.tblCamp.fieldvalues['CmpYr'];
dmAvon1.tblCamp.Next;
end
else
begin
dmAvon1.tblCamp.Next;
end;
end;
end;
dmAvon1.tblCamp.Close;

end;

procedure TfrmCampSrep.Button3Click(Sender: TObject);
var
i, x, y: integer;

begin
repsarray := nil;
if ComboBox1.Text = '' then
begin
showmessage('Team Area must be selected');
ComboBox1.SetFocus;
Exit;
end
else
begin
taid := strtoint(comboBox1.text);
end;

if ComboBox2.Text = '' then
begin
showmessage('Campaign Year must be selected');
ComboBox2.SetFocus;
Exit;
end;

if ComboBox3.Text = '' then
begin
showmessage('Campaign Number must be selected');
ComboBox3.SetFocus;
Exit;
end;

x := 390;
y := 130;
rep_count := 0;
i := 1;

while i <> ComponentCount + 1 do
begin
if Components.Name = 'RadioGroup' + inttostr(i) then
begin
TRadiogroup(Components).Destroy;
end
else
begin
inc(i);
end;
end;

dmAvon1.SQLCampSrep.Close;
dmAvon1.SQLCampSrep.Parameters.ParamByName('Taid').Value := taid;
dmAvon1.SQLCampSrep.Open;
rep_count := dmAvon1.SQLCampSrep.RecordCount;
SetLength(repsarray, rep_count);
dmAvon1.SQLCampSrep.First;

if rep_count = 0 then
begin
showmessage('No data to display.');
exit;
end;

for i := 0 to rep_count - 1 do
begin
with TRadioGroup.Create(self) do
begin
parent := self;
left := x;
top := y;
width := 300;
height := 41;
columns := 3;
items.add('Completed');
items.add('Missed');
items.add('Suspended');
caption := ' ' + dmAvon1.SQLCampSrep.fieldvalues['SRepFNm'] +
' ' + dmAvon1.SQLCampSrep.fieldvalues['SRepLNm'] + ' ';
color := clMoneyGreen;
end;
repsarray := TRadioGroup(Self);
y := y + 48;
dmAvon1.SQLCampSrep.next;
end;
dmAvon1.SQLCampSrep.close;
end;

procedure TfrmCampSrep.Button2Click(Sender: TObject);
begin
frmMainMenu.show;
frmCampSrep.close;
frmCampSrep.release;
frmCampSrep := nil;
end;

end.

 
you can only select 1 radio button in a group at a time.
you need to use check boxes..
 
2. Problem
We have been able to create the above but cannot do the following:
2.1. Only press one of the three buttons (not be able to select all three buttons).

2.2. If there are 50 SR’s how do we do a select all for say, the completed button (or missed button etc), or do a deselect all. (we can only press one button at a time).

2.1 says press only one, but 2.2 says select all?

tempyear := dmAvon1.tblCamp.fieldvalues['CmpYr'];
ComboBox2.Items.add(inttostr(tempyear));
while not dmAvon1.tblCamp.Eof do
begin
if dmAvon1.tblCamp.fieldvalues['CmpYr'] <> tempyear then
begin

why go through the whole database? Why not a SQL:
SELECT CMPYR FROM CAMPAIGN WHERE CMPYR <> ' + tempyear
then add all results? Or since you update tempyear each time, maybe the SQL = SELECT DISTINCT CMPYR AS CMPYR WHERE ...(so there aren't duplicate years?)

To update to the database use a SQL Query:
UPDATE SRCAMPAIGN (SRNUM, CAMPAIGN, STATUS) VALUES (1, 2002, 3)
then ExecSQL



Leslie
landrews@metrocourt.state.nm.us

SELECT * FROM USERS WHERE CLUE > 0
No Rows Returned
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top