A dual use of a lookup query

A dual use of a lookup query

Usually in your application you use two different types of lookup query; the first one is for retrieving a page of records (or all records) to populate a pick list, the other one is to retrieve a single record, i.e. for decoding a code description while user is typing it in a textbox. So, if your queries are dynamically configured and are stored in a DB, you mustduplicate the list of query statements. So you’ll use in the first in the first situation a query like:


In the other situation you’ll use a query like:


But you can use just one query structured in dual mode:


When you want to populate a pick list you’ll pass to the second parameter simply a 1 and all records will be retrieved. When you want to decode a single value, you must pass the code to the first parameter and a 0 to the second one. So, if all your queries use always one parameter to decode value, you can write a standard (dual) lookup routine like this:

Dim lConn As ADODB.ConnectionDim lCmd As ADODB.CommandDim lRs As ADODB.RecordsetDim lParAllRecords as LongDim lParSingleRecord as LongSet lConn = New ADODB.ConnectionlConn.Open "Provider=SQLOLEDB.1;Persist Security Info=False;User ID=sa;Initial " _    & "Catalog=PUBS;Data Source=(local)"lConn.CursorLocation = adUseClientSet lCmd = New ADODB.CommandSet lCmd.ActiveConnection = lConnlCmd.CommandText = txtStatement.Text'if you want all records:lParAllRecords = 1lParSingleRecord = 0 'not important in the first use'if you want a single record:lParAllRecords = 0lParSingleRecord = "Germany" 'the correct value to retrieve one recordlCmd.Parameters(0).Value = lParSingleRecordlCmd.Parameters(1).Value = lParAllRecordsSet lRs = lCmd.Execute

Share the Post:
XDR solutions

The Benefits of Using XDR Solutions

Cybercriminals constantly adapt their strategies, developing newer, more powerful, and intelligent ways to attack your network. Since security professionals must innovate as well, more conventional endpoint detection solutions have evolved

AI is revolutionizing fraud detection

How AI is Revolutionizing Fraud Detection

Artificial intelligence – commonly known as AI – means a form of technology with multiple uses. As a result, it has become extremely valuable to a number of businesses across

AI innovation

Companies Leading AI Innovation in 2023

Artificial intelligence (AI) has been transforming industries and revolutionizing business operations. AI’s potential to enhance efficiency and productivity has become crucial to many businesses. As we move into 2023, several

data fivetran pricing

Fivetran Pricing Explained

One of the biggest trends of the 21st century is the massive surge in analytics. Analytics is the process of utilizing data to drive future decision-making. With so much of

kubernetes logging

Kubernetes Logging: What You Need to Know

Kubernetes from Google is one of the most popular open-source and free container management solutions made to make managing and deploying applications easier. It has a solid architecture that makes

ransomware cyber attack

Why Is Ransomware Such a Major Threat?

One of the most significant cyber threats faced by modern organizations is a ransomware attack. Ransomware attacks have grown in both sophistication and frequency over the past few years, forcing

data dictionary

Tools You Need to Make a Data Dictionary

Data dictionaries are crucial for organizations of all sizes that deal with large amounts of data. they are centralized repositories of all the data in organizations, including metadata such as