1
votes

I have a text box controlling a combo box in turn controlling 4 text boxes.

The first text box is filled by a user or append query with a four digit store number.

The combo box is populated with the following query.

SELECT Vendors.IP
FROM Vendors
WHERE (((Vendors.Store)=[Forms].[Project Details].[Store]));

That combo box then populates the text boxes.

=DLookUp("IPPhone","Vendors","IP='" & [Forms]![Project Details]![cboIP] & "'")

"IPPhone" is actually 4 separate values (1 for each text box) but they are redacted for simplicity. This dlookup works perfectly well for most Vendors.

But there is one which does not seem weird at all, call him "Mr McTrouble". When he is selected from the drop down all 4 text boxes show "#ERROR". He's the only one of about 400 vendors to cause this. I've tried deleting him using the forms I created and re-entering him. Tried doing so in the back end table itself, no luck. With him those boxes always show #ERROR.

The combo box is a vendor name drawn from a table with the following fields:

Store    Vendor    IP            IPPHONE
1111    000001    John Johnson   111-111-1111
2222    000002    Mike           111-111-1112
2222    000003    Frankie Frank  111-111-1113
3333    000004    Joe Bob        111-111-1114
4444    000005    Smith Smith    111-111-1115
5555    000006    Mr McTrouble   111-111-1116

Date types on the table are:

Number  Number    Text            Text

The other fields here then populate the text boxes.

What am I missing here?

Is there an easier way to do this?

1
I feel like to answer your question we would need specific information about the non-working record and a single working record. Otherwise it is going to be difficult to determine the cause.Newd

1 Answers

1
votes

There is probably a single quote in the Vendor's name, like O'Donnell or O'Malley. The code that builds your sql clause also uses single quotes, resulting in an improperly formatted string looking like this: IP='O'Malley'

Try:

=DLookUp("IPPhone","Vendors","IP=""" & [Forms]![Project Details]![cboIP] & """")

I replaced each single quote with two double quotes. In VBA, this is the weird way double-quotes are escaped.

A better solution, assuming Vendor is a Primary Key for Vendor.

  • combo RowSource: SELECT Vendors.Vendor,Vendors.IP [... the rest of your SQL]
  • combo ColumnCount: 2
  • combo ColumWidths: 0;1.5 (the zero hides the first column in the combo)
  • =DLookUp("IPPhone","Vendors","Vendor=" & [Forms]![Project Details]![cboIP])

Primary Keys should be used to lookup values, if available.