Group:  Microsoft Access ยป microsoft.public.access.formscoding
Thread: simple dlookup

Geek News

simple dlookup
tina 11/20/2008 11:10:03 AM
Hi
I am trying to understand dlookup I am used to vlookup in excel but can't
seem to get it in access
I would like to lookup field both in form data and see if it is in table
detail in field also called both
both are text fields
Dim test As String
test = DLookup([both], "detail", [both] = Me.both)
If IsNull(test) Then
MsgBox -"your lot number is wrong"
I did get some help when trying to lookup to fields but to try and make
things simplier i am now trying this .I have confused myself about Dlookup
Thanks
Tina
End If
Re: simple dlookup
"Keith Wilby" <here[ at ]there.com> 11/20/2008 11:45:01 AM
"tina" <tina[ at ]discussions.microsoft.com> wrote in message
news:005C6262-8799-4FD8-B4F1-5D496A37943C[ at ]microsoft.com...
[Quoted Text]
>
> test = DLookup([both], "detail", [both] = Me.both)

Try

test = DLookup([both], "detail", "[both] = ' " & Me.both & " ' ")

Keith.

Re: simple dlookup
Stefan Hoffmann <ste5an[ at ]ste5an.de> 11/20/2008 11:54:41 AM
hi Tina,

tina wrote:
[Quoted Text]
> Dim test As String
> test = DLookup([both], "detail", [both] = Me.both)

test = DLookup("[both]", _
"detail", _
"[both] = '" & Replace(Me![both], "'", "''") & "'")


mfG
--> stefan <--
Re: simple dlookup
"Douglas J. Steele" <NOSPAM_djsteele[ at ]NOSPAM_gmail.com> 11/20/2008 12:19:55 PM
<picky>
Both Keith and Stefan missed the fact that you've declared test as a String.

The DLookup function will return Null if there is no match, and Null values
cannot be assigned to String variables. (The only data type that can be
assigned a Null value is the Variant).

You either need to redefine test as Variant, or else wrap the Nz value
around your DLookup call to set it to a string value if Null is returned.

Incidentally, Keith's answer was "exagerated" so that you could see the
difference between the single quotes and double quotes. In actual use, you
would NOT have the spaces. In other words, instead of

test = DLookup([both], "detail", "[both] = ' " & Me.both & " ' ")

you'd actually use

test = DLookup([both], "detail", "[both] = '" & Me.both & "'")

Stefan's answer is safer: it will handle cases where there's an apostrophe
in what's in Me!Both. Exagerated for clarity, he had

test = DLookup("[both]", _
"detail", _
"[both] = ' " & Replace(Me![both], " ' ", " ' ' ") & " ' ")

Incorporating my suggestion, you should use

test = Nz(DLookup("[both]", _
"detail", _
"[both] = '" & Replace(Me![both], "'", "''") & "'"), "No
Value")

</picky>



--
Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(no e-mails, please!)


"tina" <tina[ at ]discussions.microsoft.com> wrote in message
news:005C6262-8799-4FD8-B4F1-5D496A37943C[ at ]microsoft.com...
[Quoted Text]
> Hi
> I am trying to understand dlookup I am used to vlookup in excel but can't
> seem to get it in access
> I would like to lookup field both in form data and see if it is in table
> detail in field also called both
> both are text fields
> Dim test As String
> test = DLookup([both], "detail", [both] = Me.both)
> If IsNull(test) Then
> MsgBox -"your lot number is wrong"
> I did get some help when trying to lookup to fields but to try and make
> things simplier i am now trying this .I have confused myself about Dlookup
> Thanks
> Tina
> End If


Re: simple dlookup
tina 11/20/2008 2:59:02 PM
Thank you so much Douglas
I really need to spend some time learning syntex but needed this urgently vb
in excel is a lot easier

"Douglas J. Steele" wrote:

[Quoted Text]
> <picky>
> Both Keith and Stefan missed the fact that you've declared test as a String.
>
> The DLookup function will return Null if there is no match, and Null values
> cannot be assigned to String variables. (The only data type that can be
> assigned a Null value is the Variant).
>
> You either need to redefine test as Variant, or else wrap the Nz value
> around your DLookup call to set it to a string value if Null is returned.
>
> Incidentally, Keith's answer was "exagerated" so that you could see the
> difference between the single quotes and double quotes. In actual use, you
> would NOT have the spaces. In other words, instead of
>
> test = DLookup([both], "detail", "[both] = ' " & Me.both & " ' ")
>
> you'd actually use
>
> test = DLookup([both], "detail", "[both] = '" & Me.both & "'")
>
> Stefan's answer is safer: it will handle cases where there's an apostrophe
> in what's in Me!Both. Exagerated for clarity, he had
>
> test = DLookup("[both]", _
> "detail", _
> "[both] = ' " & Replace(Me![both], " ' ", " ' ' ") & " ' ")
>
> Incorporating my suggestion, you should use
>
> test = Nz(DLookup("[both]", _
> "detail", _
> "[both] = '" & Replace(Me![both], "'", "''") & "'"), "No
> Value")
>
> </picky>
>
>
>
> --
> Doug Steele, Microsoft Access MVP
> http://I.Am/DougSteele
> (no e-mails, please!)
>
>
> "tina" <tina[ at ]discussions.microsoft.com> wrote in message
> news:005C6262-8799-4FD8-B4F1-5D496A37943C[ at ]microsoft.com...
> > Hi
> > I am trying to understand dlookup I am used to vlookup in excel but can't
> > seem to get it in access
> > I would like to lookup field both in form data and see if it is in table
> > detail in field also called both
> > both are text fields
> > Dim test As String
> > test = DLookup([both], "detail", [both] = Me.both)
> > If IsNull(test) Then
> > MsgBox -"your lot number is wrong"
> > I did get some help when trying to lookup to fields but to try and make
> > things simplier i am now trying this .I have confused myself about Dlookup
> > Thanks
> > Tina
> > End If
>
>
>
Re: simple dlookup
"Keith Wilby" <here[ at ]there.com> 11/20/2008 4:46:09 PM
"Douglas J. Steele" <NOSPAM_djsteele[ at ]NOSPAM_gmail.com> wrote in message
news:uDgeNpwSJHA.6060[ at ]TK2MSFTNGP06.phx.gbl...
[Quoted Text]
> <picky>

Better to be picky than wrong ;)

Keith.

Re: simple dlookup
"Mike Painter" <mddotpainter[ at ]sbcglobal.net> 11/20/2008 10:54:47 PM
tina wrote:
[Quoted Text]
> Thank you so much Douglas
> I really need to spend some time learning syntex but needed this
> urgently vb in excel is a lot easier
>
I don't thin vlookup is a vb function, it was in visicalc, the very first
spreadsheet.
One of my students wrote an entire payroll system in Visicalc in the early
80's on a TRS-80.
vlookup was used a lot for teh tax tables.
He kept asking for another problem.


Home | Search | Terms | Imprint Contact
Newsgroups Reader - provided by WiredBox.Net