Page 1 of 1

Show results in combo box

PostPosted: Sun Oct 18, 2015 9:35 am
by HackinHoodLogicsTm
Hello Neobookers can someone help me on this. I have a database with table with the following fields "Firstname" and "LastName"

I have created a combo box and wants it to display the records in the two fields Firstname and lastname all in one line in the combo box like
[firstname] [lastname]
Say John Dough

But when I try my best its not working. Pls can anyone help me on this

Re: Show results in combo box

PostPosted: Sun Oct 18, 2015 10:05 am
by Gaev
HackinHoodLogicsTm:

But when I try my best its not working.

Why don't you post what you tried ? ... and tell us how the result differs from expectation.

Re: Show results in combo box

PostPosted: Sun Oct 18, 2015 10:55 am
by HackinHoodLogicsTm
I created a combo box and assigned a
[ firstname ] [ lastname ]

Into the list itmm
And then created a button and assigned this code on buttonClick

dpbFileToVar "Database" "Table" "First Name" " [ firstname ] " and the delimiters

Then copied the same code below but this time I placed the last name field in the variable " [ lastname ] "

But the combo box displays the first name on the first line and last name on the second line which is not what I want

I want the two name to display on the first line like
John Dough

Not
John
Dough

Hope u understand now

Re: Show results in combo box

PostPosted: Sun Oct 18, 2015 1:10 pm
by Gaev
You can only specify one field in the dbpFieldToVar command ... so you can ...

1) either create another field in your Database Table (say FullName) ... which you auto-populate (from FirstName and LastName) every time a record is added or updated ... then use ...
Code: Select all
dbpFieldToVar "yourDatabase" "yourTable" "FullName" "[FullNames]" "Delimiter=[#13]"

... where [FullNames] is the variable to contain the values of your ComboBox.

2) or you can dynamically create this list by Looping through every record ...
Code: Select all
... place any dbpQuery command here if you don't want to include every record

... get record count
SetVar "[LoopCount]" "[yourDatabase.yourTable.$RecCount]"

... position at first record
dbpFirst "yourDatabase" "yourTable"

... loop through all records
SetVar "[FullNames" ""
Loop "1" "[LoopCount]" "[thisIteration]"
   ... construct and add list entry
   SetVar "[FullNames]" "[FullNames][#13][FirstName] [LastName]"
   ... advance to next record
   dbpNext "yourDatabase" "yourTable"
EndLoop
... remove very first [#13]
StrLen "[FullNames]" "[FullNamesLength]"
SubStr "[FullNames]" "2" "[FullNameslength]-1" "[FullNames]"

Re: Show results in combo box

PostPosted: Sun Oct 18, 2015 3:47 pm
by HackinHoodLogicsTm
Thanks Bro. It really helped. U te genius

Re: Show results in combo box

PostPosted: Mon Oct 19, 2015 3:43 am
by stu
You could also create a view on your database and concatenate the two columns...