Solved

DLOOKUP Equivalent

Posted on 2014-04-07
5
187 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
5 Comments
 
LVL 63

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

MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

Question has a verified solution.

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

Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

734 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