NetTalk Central

Author Topic: Field Lookup Function  (Read 1389 times)

DonnEdwards

  • Jr. Member
  • **
  • Posts: 56
    • View Profile
    • Insights and Rants
    • Email
Field Lookup Function
« on: June 29, 2021, 06:13:40 AM »
I have a NTWS browse form (Invoices) that I want to filter by customer number. So I created a Memory form "Filter_Invoices" that has browseInvoice as a child form.

At the moment I can display the Customer number in the memory form's header, by doing the following:

Heading: 'Invoices for Customer #' & p_web.GSV('cus:CustomerId')

What I really want is
Heading: 'Invoices for ' & Lookup('CustomerName','Customer','CustomerId='p_web.GSV('cus:CustomerId'))
so that the heading is shown as "Invoices for Acme Widgets Inc" or whatever.

Visual Basic has a function called DLookup("Field","Table","Where clause") and the Where clause can be a whole big SQL statement. I'm looking for something a little more modest. Does such a function exist in Clarion/NetTalk, or will I have to write one?

All suggestions welcome.
If you're happy with your security, then so are the bad guys

Bruce

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 11150
    • View Profile
Re: Field Lookup Function
« Reply #1 on: June 29, 2021, 07:08:46 AM »
Hi Donn,

>> 'Invoices for ' & Lookup('CustomerName','Customer','CustomerId='p_web.GSV('cus:CustomerId'))

It's not quite as simple as that, but it's not terrible.

A) in the form heading field put the name of a local variable - ie somethign you create in the data pad. like donn:header

B) in the embeditor go to the
Heading  Routine

this is where you can set donn:header to whatever you want.

So, now you have a couple options to load the related record, and get the customer name. first the obvious;

Access:Customer.Openfile()
Access:Customer.Usefile()
cus:CustomerId = p_web.GSV('cus:CustomerId')
Access:Customer.Fetch(cus:idkey)
donn:header =  'Invoices for ' & cus:CustomerName
Access:Customer.Close()

If you have myTable then it's a bit simpler;

mt  myTable
  mt.get(Customers,'id',p_web.GSV('cus:CustomerId'))
  donn:header =  'Invoices for ' & cus:CustomerName


there's also a p_web._LoadRecord method
  p_web._Loadrecord(Customers, cus:IdKey,p_web.GSV('cus:CustomerId')
  donn:header =  'Invoices for ' & cus:CustomerName

which would also probably work (not tested though)

Cheers
Bruce

 



DonnEdwards

  • Jr. Member
  • **
  • Posts: 56
    • View Profile
    • Insights and Rants
    • Email
Re: Field Lookup Function
« Reply #2 on: June 29, 2021, 09:26:38 AM »
Thanks Bruce! I'll give each method a try.

Edit: I discovered that loc:Heading was already in use. I guess that's why your example didn't use it. ;-)
.OpenFile() is a typo. Should read .Open()
Otherwise, code works perfectly.
« Last Edit: June 30, 2021, 02:04:50 AM by DonnEdwards »
If you're happy with your security, then so are the bad guys