We help IT Professionals succeed at work.

I need to replace a DLookup with an ADO code

Delirious
Delirious asked
on
Medium Priority
467 Views
Last Modified: 2010-05-18
Here is my DLookup code.

If Not IsNull(DLookup("[AUFNR]", "[P4S_WRITE_USER_Z_R3_AUFK_TBL]", "[txtCharge_Code] =" & Me.txtCharge_Code) & "") Then
   MsgBox "This is a invalide code.  Please try again.", vbOKOnly
   End
End If

How would I replace this with ADO code?

Thanks
Comment
Watch Question

Commented:

You can still use that same code with ADO

Gary

Commented:
Or are you talking about something else?

Author

Commented:
Maybe...

If I needed this same functionality without using DLookup.  What would the code look like.

ADODB.Connection
ADODB.recordset
Dim.....
Dim....

CERTIFIED EXPERT

Commented:
Gary I think Delirious wants to open an ADO recordset - correct ?
CERTIFIED EXPERT

Commented:
Delirious - you just got in before me!

Commented:
R U 2 related?
CERTIFIED EXPERT
Commented:
would be something like


dim r as new adodb.recordset
dim sql as string
sql = select AUFNR from P4S_WRITE_USER_Z_R3_AUFK_TBL where txtCharge_Code = '" & Me.txtCharge_Code "'"

r.open (sql,currentproject.connection)
r.movefirst
if isnull(r(0)) then
 MsgBox "This is a invalide code.  Please try again.", vbOKOnly
end if

my ado may not be 100% - do you get the idea ?


Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts
CERTIFIED EXPERT

Commented:
<R U 2 related? >  WHY?
Commented:
Hi Datrias,
> if isnull(r(0)) then
>  MsgBox "This is a invalide code.  Please try again.", vbOKOnly
> end if
That should be more like:

if rs.eof and rs.bof
 MsgBox "This is a invalide code.  Please try again.", vbOKOnly
end if
Dave :-)
CERTIFIED EXPERT

Commented:
oh yeah - of course Dave - good spot !

Author

Commented:
Ok I'm getting there.  I'm working on the sql statement...

Author

Commented:
Ok great!  Thanks for the help.  I'll split the points.
CERTIFIED EXPERT

Commented:
fair enough

Commented:
Similar names thats all!
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.