The Forums on slxdeveloper.com are now retired. The forum archive will remain available for the time being. Thank you for your participation on slxdeveloper.com!
|
|
Can't get lookup field to work properly
Posted: 16 Apr 08 7:20 AM
|
Hi,
I'm having problems with getting a custom lookup field to work.
I have create a new table and main view called 'RAN'. I have added a tab to it called 'RAN contacts'. I want to create a lookup that will lookup the contact table and return the contactID to the 'RAN Contacts' table. All I can get the lookup to work, but only if the lookup criteria is the same as the data being entered into the table i.e. if I search on ContactID, it returns ContactID. What I really want is to lookup the contact's lastname and populate the table with their ContactID. Here are the values I am using:
lookup : Contact:Lastname LookupID: RAN_Contact:ContactID LookupMainTable: Contact Lookup Mode: lmTable Text: RAN_Contact:ContactID
What am I doing wrong? |
|
|
|
Re: Can't get lookup field to work properly
Posted: 16 Apr 08 7:34 AM
|
I think that is just the way it works. I am on 7.0.1, and the only way I have been able to get it to work (even working with my Vendor) is to save the contact id to the table. Create a hidden text box that stores the value of the id field from the database. Then I have an event in the onChange of the form that takes that id and does a lookup on the contact table to get me the name, and then I set the text value of the lookup field to the contact name. here is an example:
Sub AXFormChange(sender) Dim strContactID
'Populate the contact name strContactID = txtContactID.Text SetContactName(strContactID) end sub
sub SetContactName(contactId) Dim objRS Dim objSLXDB Dim strSQL Dim ContactName
If (contactId <> "") Then Set objSLXDB = New SLX_DB Set objRS = objSLXDB.GetNewRecordSet strSQL = "Select CONTACTNAME FROM C_CONTACT WHERE C_CONTACTID = '" & contactId & "'" objRS.Open strSQL, objSLXDB.Connection
If not (objRS.EOF Or objRS.BOF) then ContactName = objRS.Fields("CONTACTNAME").value End If
objRS.Close Set objRS = Nothing End If
lveRNAContact.Text = ContactName end sub
Hopefully someone else will let us know if there is a better way - because this always seemed absurd to me. Brian |
|
|
|
Re: Can't get lookup field to work properly
Posted: 16 Apr 08 7:38 AM
|
Hi Brian,
I'll give it a go.
I'm far from an expert...hell, i'm not even a developer! I thought it would have been straightforward to look up one value and return another. All I want to do is look up a contact by their name and return their ContactID. *sniff sniff* |
|
|
|
Re: Can't get lookup field to work properly
Posted: 16 Apr 08 1:18 PM
|
Use a LookupEdit Control.....the ID field is returned in the LookupID property.....and the Contact's Name is returned in the .TEXT property.
Now that you have the ID value of the user selected contact, script away. * belch belch* |
|
|
|
Re: Can't get lookup field to work properly
Posted: 17 Apr 08 5:46 AM
|
Hi RJ,
Thanks for the help. I've got this working now.
I would now like to be able to double click on a datagrid row ('grdContacts') and for it to take me to their contact detail screen. Do you have any idea how I can do this? I tried the following code but nothing happens when I click on the row:
'Including Script - System:SLX_Common 'Including Script - System:SLX Activity Support 'Including Script - System:SLX Database Support option explicit
Sub CallContactDetailView OpenMainViewFromGridCrntID grdContacts, "CONTACTID", "System:Contact Details", 1, True 'DNL End Sub
Sub grdContactsDblClick(Sender) CallContactDetailView End Sub
Thanks! |
|
|
|
Re: Can't get lookup field to work properly
Posted: 18 Apr 08 8:57 AM
|
Sub returnfromdoubleclick DIM CID CID = "" & Gridname.GetCurrentField("CONTACTID") If CID > "" THEN Application.basicfunctions.setcurrentcontactID CID END SUB |
|
|
|