A Microsoft Office (Excel, Word) forum. OfficeFrustration

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » OfficeFrustration forum » Microsoft Access » Using Forms
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

DLookup



 
 
Thread Tools Display Modes
  #1  
Old April 14th, 2008, 07:53 PM posted to microsoft.public.access.forms
KBDB
external usenet poster
 
Posts: 36
Default DLookup

In my VBA code I have a DLookup statement which is:

Private Sub custid_AfterUpdate()

Me.CustomerName = DLookup("[Customer Name]", "Customer File", _
"[Cust ID] = " & Me.CustID)

End Sub


I run this and I get this error:
Run Time Error 2471

The expression you entered as a query parameter produced this error:
'DT'

DT is the custID selected from the combo box.

I just don't understand what this error is trying to tell me.
Could you help?
Have you got any ideals?

Thanks,
Kathleen

  #2  
Old April 14th, 2008, 08:03 PM posted to microsoft.public.access.forms
fredg
external usenet poster
 
Posts: 4,386
Default DLookup

On Mon, 14 Apr 2008 11:53:01 -0700, KBDB wrote:

In my VBA code I have a DLookup statement which is:

Private Sub custid_AfterUpdate()

Me.CustomerName = DLookup("[Customer Name]", "Customer File", _
"[Cust ID] = " & Me.CustID)

End Sub

I run this and I get this error:
Run Time Error 2471

The expression you entered as a query parameter produced this error:
'DT'

DT is the custID selected from the combo box.

I just don't understand what this error is trying to tell me.
Could you help?
Have you got any ideals?

Thanks,
Kathleen


The syntax needed is determined by the datatype of the criteria field.
If the value stored in the [Cust ID] field is DT, then it has to be
text. Your syntax was for a Number datatype.

Me.CustomerName = DLookup("[Customer Name]", "Customer File", _
"[Cust ID] ='" & Me.CustID & "'")

See VBA help on DLookup as well as
'Restrict data to a subset of records'
for more information on the proper syntax needed for the various
datatypes.

--
Fred
Please respond only to this newsgroup.
I do not reply to personal e-mail
  #3  
Old April 14th, 2008, 08:04 PM posted to microsoft.public.access.forms
Dirk Goldgar
external usenet poster
 
Posts: 2,529
Default DLookup

"KBDB" wrote in message
...
In my VBA code I have a DLookup statement which is:

Private Sub custid_AfterUpdate()

Me.CustomerName = DLookup("[Customer Name]", "Customer File", _
"[Cust ID] = " & Me.CustID)

End Sub


I run this and I get this error:
Run Time Error 2471

The expression you entered as a query parameter produced this error:
'DT'

DT is the custID selected from the combo box.

I just don't understand what this error is trying to tell me.



It's trying to tell you that your [Cust ID] field is text, not a number, and
so any value you want to match it against must be enclosed in quotes. Try
this:


Me.CustomerName = _
DLookup("[Customer Name]", "Customer File", _
"[Cust ID] = '" & Me.CustID & "'")

Note that I've put single-quotes (') around the embedded CustID. That
should work so long as the CustID will never contain the single-quote
character.

By the way, your programming would be a lot easier if you didn't have spaces
in your field and table names. You wouldn't have to put square brackets
around all those names.

--
Dirk Goldgar, MS Access MVP
www.datagnostics.com

(please reply to the newsgroup)

  #4  
Old April 14th, 2008, 09:38 PM posted to microsoft.public.access.forms
KBDB
external usenet poster
 
Posts: 36
Default DLookup

Hi,

Something so simple can be so hard sometimes.
Thanks, I won't forget this one again.

-Kathleen

"fredg" wrote:

On Mon, 14 Apr 2008 11:53:01 -0700, KBDB wrote:

In my VBA code I have a DLookup statement which is:

Private Sub custid_AfterUpdate()

Me.CustomerName = DLookup("[Customer Name]", "Customer File", _
"[Cust ID] = " & Me.CustID)

End Sub

I run this and I get this error:
Run Time Error 2471

The expression you entered as a query parameter produced this error:
'DT'

DT is the custID selected from the combo box.

I just don't understand what this error is trying to tell me.
Could you help?
Have you got any ideals?

Thanks,
Kathleen


The syntax needed is determined by the datatype of the criteria field.
If the value stored in the [Cust ID] field is DT, then it has to be
text. Your syntax was for a Number datatype.

Me.CustomerName = DLookup("[Customer Name]", "Customer File", _
"[Cust ID] ='" & Me.CustID & "'")

See VBA help on DLookup as well as
'Restrict data to a subset of records'
for more information on the proper syntax needed for the various
datatypes.

--
Fred
Please respond only to this newsgroup.
I do not reply to personal e-mail

  #5  
Old April 14th, 2008, 09:44 PM posted to microsoft.public.access.forms
KBDB
external usenet poster
 
Posts: 36
Default DLookup

Hi,

Thank you. I knew it would be something so simple.

I have to put those spaces in so I can tell whats file stuff. I am just
starting to code so I get real confused alot. I'm sure after this project I
will do things different next time.

-Kathleen

"Dirk Goldgar" wrote:

"KBDB" wrote in message
...
In my VBA code I have a DLookup statement which is:

Private Sub custid_AfterUpdate()

Me.CustomerName = DLookup("[Customer Name]", "Customer File", _
"[Cust ID] = " & Me.CustID)

End Sub


I run this and I get this error:
Run Time Error 2471

The expression you entered as a query parameter produced this error:
'DT'

DT is the custID selected from the combo box.

I just don't understand what this error is trying to tell me.



It's trying to tell you that your [Cust ID] field is text, not a number, and
so any value you want to match it against must be enclosed in quotes. Try
this:


Me.CustomerName = _
DLookup("[Customer Name]", "Customer File", _
"[Cust ID] = '" & Me.CustID & "'")

Note that I've put single-quotes (') around the embedded CustID. That
should work so long as the CustID will never contain the single-quote
character.

By the way, your programming would be a lot easier if you didn't have spaces
in your field and table names. You wouldn't have to put square brackets
around all those names.

--
Dirk Goldgar, MS Access MVP
www.datagnostics.com

(please reply to the newsgroup)

 




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump


All times are GMT +1. The time now is 07:59 PM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 OfficeFrustration.
The comments are property of their posters.