Solved

DLOOKUP Equivalent

Posted on 2014-04-07
5
176 Views
Last Modified: 2014-04-09
I am in the process of converting from ms access.  I have a code that looks at a database on txtreportedby.text_LostFocus  event.  It querys a db call Advisories.  The way the select statement is: SELECT Name from Advisory WHERE Name = '" +txtreportedby.text+ "'.  If the name is in the db, it will popup form "Advisories". The DLOOKUP I have from access is:

        'If no match is found do nothing
         If IsNull(DLookup("[name]", "Advisories", "[name]='" & Me![txtReportedBy] & "'")) Then
        Exit Sub
        End If

Open in new window

Any help would be greatly appreciated as I have quite a few DLOOKUP I am having to convert.  I have searched around and there is no place out there that comes close to the experts on here.  So thanks in advance!!  Also I am using VB.NET not C++.
0
Comment
Question by:russell12
  • 2
  • 2
5 Comments
 
LVL 62

Expert Comment

by:Fernando Soto
ID: 39984861
Well As you may know there is no equivalent function in Visual Basic .Net. You will need to access the database by A different means. You state in your question, "I am in the process of converting from ms access", to what type of database? In order to answer your question we will need to know this.
0
 
LVL 44

Accepted Solution

by:
AndyAinscow earned 500 total points
ID: 39985151
Basically you need to write your own DLOOKUP equivalent.  The one you have takes the field name, the table (or query) name and a where condition.  So your function would be something like this
DLOOKUP(fld, tbl, cond)
{
check things are passed in
string s = "SELECT " + fld + " FROM " + tbl + " WHERE " + cond
get the database opened or retrieve an existing connection
run the query against the database
store the contents of the returned field
close up and return what should be returned
}
0
 
LVL 2

Author Comment

by:russell12
ID: 39985764
We use access for a front end and use SQL Server for backend.  I was already thinking I was going to have use a select statement, but my question is, do I have to put the result in a textbox, or could I dim the variable?  I am not getting anything for a textbox, just if the name exist in advisories, open a form.  I hope this is making sense.  I use VB Studio 2013 Pro, using VB
0
 
LVL 44

Expert Comment

by:AndyAinscow
ID: 39985779
>>do I have to put the result in a textbox, or could I dim the variable?

Either, whichever makes the most sense for using the retrieved value further in your app.
0
 
LVL 2

Author Closing Comment

by:russell12
ID: 39988719
Thank you!!
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…

863 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

25 Experts available now in Live!

Get 1:1 Help Now