TheunisP
Posts: 342
|
Posted: 12/28/2005, 4:36 PM |
|
Ok - here is the background:
- you have a update/insert form
- 1 of the fields is a listbox that is populated from another table e.g. Country, Town whatever...
- Now you want the user to pick from the list, if he's value is not listed you want him to provide it for you in a text box
- the slammer is 1) the value must be added to the other table if it is new 2) ignored if it is duplicate and the correct key must be extracted from the other table although he typed it and didn't select it 3) business as usual if he selected it from the list
steps:
- add the list box as normal
- add a text box next to it give it a name e.g. txtNewOne
and add this code into the BeforeBuildInsert (and Update event)
Dim strTemp
strTemp = CCGetParam("txtNewOne","") ' get text box value
if strTemp <> "" then ' check if empty
if CCDLookUp( "country_key", "countries", "country_name = '" & strTemp & "'", DBobjConnMain) = 0 then ' check 4 duplicate
DBobjConnMain.Execute "INSERT INTO countries (country_name) VALUES ('" & strTemp & "')" ' if not duplicate add
end if
t_Record.DataSource.f_MyCountry.value = CCDLookUp( "country_key", "countries", "country_name = '" & strTemp & "'", DBobjConnMain) ' get the key of the newly added value
end if
Validation needs to be done to check if either was filled in (if the field is essential) - quick and dirty:
Dim strTemp
strTemp = CCGetParam("txtNewOne","")
If IsEmpty(t_Record.f_MyCountry.Value) AND strTemp = "" Then
t_Record.Errors.AddError("Must pick a Country or enter a new Country")
End if
Hope this helps someone
|
|
|
|