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. |
|
|
Thread Tools | Display Modes |
#1
|
|||
|
|||
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
|
|||
|
|||
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
|
|||
|
|||
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
|
|||
|
|||
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
|
|||
|
|||
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 | |
|
|