The expression:
=IIf(([cbo1]IS NOT NULL),DLookUp("[Thing1]","[tbl1]","[cbo1]= " & [Forms]![frm1]![cbo1]), "")
returns "#Error" when I try to use it to populate a text box based on the value of a combo box. The values in the combo box are all words, so setting
=IIF([cbo1]>0
in the first part creates a different error. I have this expression on a different part of the form and it works fine for numerical values.
=IIf(([txt1]>0),DLookUp("[thing1]","[tbl11]","[Thing2]= " & [Forms]![Frm1]![txt1]),"")
What am I missing on the one dealing with text?
IS NOT NULL is supported in Access SQL, but not in VBA expressions. Use IsNull().
=IIf(Not IsNull([cbo1]), DLookUp("[Thing1]", "tbl1", "[cbo1]=" & [cbo1]), "")
Note the DLookUp expression requires that tbl1 includes a numeric field named cbo1, the same as your combo box name. That could be correct, but it looks suspicious to me. Double-check that field name if you get another error.
Related
Obviously I am not an Access expert or I would not be asking this question. I created a small database with several tables. On a form, there are several combo boxes for the user to choose different combinations of medium, paper, sizes, etc. I have already created an expression that returns the correct value I need, but I cannot figure out how to get this value into the correct field on the table to store with the record the form is creating. Below are screen shots of the form and a couple of the tables. I have also included the expression I am using. I need the value that the expression returns to go into tbl1Artwork and populate the ArtWorkSKU field.
Expression:
=Left([PieceName],4) & [cbxArtist].Column & [cbxMedium].Column & [cbxPaperType].Column & [cbxPrintType].Column & [cbxSize].Column
The ArtWorkSKU text box is unbound as I had to type the expression in there. I am not sure if this is the correct way to accomplish the goal. In the tables below, except for the PK, all fields are Short Text.
All guidance is greatly appreciated.
Saving calculated data is usually not necessary and can be risky. Saved value can become 'out of sync' with raw data. Value can be calculated when needed.
Saving calculated data requires code (macro or VBA).
Can be as simple as Me!fieldname = Me.controlname.
Real trick is figuring out what event(s) to put code into. In your case, most likely form BeforeUpdate.
Advise not to use spaces nor punctuation/special characters (underscore only exception) in naming convention. Better would be ArtworkSKU or ArtworkSKUnum or Artwork_SKU_Num.
Create the following function in VBA:
Function UpdateSKU()
Me.ArtWorkSKU = Left(Me.[PieceName],4) & Me.[cbxArtist].Column(3) & _
Me.[cbxMedium].Column(2) & Me.[cbxPaperType].Column(2) & _
Me.[cbxPrintType].Column(2) & Me.[cbxSize].Column(2)
End Function
Then, on the form, update the After Update event property (not vba) of each "feeder" control to:
After Update: =UpdateSKU()
I've seen similar questions but the provided answers couldn't solve my problem.
In access I created a form.
From a listbox you can select a name. The names are listed in the table tNames in the column names_combined (last name, given name) . In two other columns last name and given name are separated.
On the right side of the listbox you can find information about the name which will be shown in text boxes.
The goal is to show the last name from table tNames.lastname by looking for tNames.names_combined.
So I tried this:
=Dlookup("lastname";"tNames";"names_compined =" & Me.listbox)
However I just get error messages in my text box.
Thanks in advance!
DLookup requires commas not colons.
This should work assuming all the names of tables/fileds and controls are correct:
=Dlookup("lastname","tNames","names_compined='" & Me.listbox & "'")
Also make sure the actual bound field of your listbox is the combined name (by the way you code says comPined).
Finally as it was pointed out in the other answer me.something will only work in the form itself or its VBA module. Everywhere else you need a global identifier.
Try with:
=Dlookup("lastname";"tNames";"names_combined = '" & Forms!YourForm!listbox & "'")
I'm trying to make a MS Access report, where I use a text box to display a field value, then have another text box indicating if the first value is higher or lower than an entry in a separate table.
The report has a record source of "Table 1", and a textbox named "txt_Value1" which displays the number in Field: "Value1". I have a second table, "Customer_Criteria" which has a field "PassValue" that I want to compare against. My expression builder statement is:
IIf([txt_Value1]<(DLookUp("[PassValue]","[Customer_Criteria]","[Customer] = 'ABC'")),"TRUE","FALSE")
This statement always returns false, regardless of what the correct logical result is.
I've tested it, writing:
IIf(1<(DLookUp("[PassValue]","[Customer_Criteria]","[Customer] = 'ABC'")),"TRUE","FALSE")
And I get the correct results. Also, if I write:
IIf([txt_Value1]< 1,"TRUE","FALSE")
I get the correct results. What am I missing to compare the textbox value vs. the Dlookup?
As I understand, both fields are numeric. Access may consider those fields as text, so for correct comparing use type conversion.
Try this:
IIf(CLng(Nz([txt_Value1],0))< _
CLng(Nz(DLookUp("[PassValue]","[Customer_Criteria]","[Customer] = 'ABC'"),0)), _
"TRUE","FALSE")
Nz required if fields may contain NULL values, in this case type conversion function will return error.
I am filtering a form named sfrWorklistFilter from a combo box named cboOpeningType. The recordsource is from an embedded query on the form. If I make a selection from the combo box the filter works fine with the following code:
Forms![sfrWorklistFilter]![cboOpeningType]
However I need to return all records when no selection is made in which case I use the following code:
Like Forms![sfrWorklistFilter]![cboOpeningType] & "*"
The filter then does not give exact matches, but all records that begin with the letter on the combo box.
I need exact matches for the record or if no selection is made all records.
Any suggestions?
EDIT remove double quotes
This should work - and you can do same thing with your other field/combobox searches
Like IIf([Forms]![sfrWorklistFilter]![cboOpeningType]<>"",[Forms]![sfrWorklistFilter]![cboOpeningType],"*")
I'm trying to write a little form which accepts some user input, and on the basis of some logic displays one of two possible other forms. Everything is working fine if I use simple, unformatted data, but I hit a problem if the data in question has an input mask of a phone number. Presumably there's a trick here to ignore formatting characters or some such?
The actual logic looks for records in a particular table whose values match the data entered. Something like this cut down example:
A form, which is not associated with any specific table, containing one data entry field, called FormFieldY, and a button whose onClick invokes a Macro whose condition looks for matching data in a table.
DCount("*","TableX","[MyColumn] = [FormFieldY] " ) > 0
Now, if I MyColumn in the table has simple text or numeric values this works just fine. However if I apply a Telephone number input mask to that column, I never get a match. I have tried applying an input mask to my form field, or typing literally into the form field a fully formatted number
(1234) 56789012
neither gives a match. However if instead I hack the macro and enter a suitable hard-coded formatted valueL
DCount("*","TableX","[MyColumn] = '(1234) 56789012'" ) > 0
It works just fine.
I think you may have two issues going on. The first is that your format property displays the parentheses when a user types in a phone number, but those parentheses are not included in the value of FormFieldY --- they are display-only.
You can verify the value of FormFieldY by assigning this code to its After Update event:
Private Sub FormFieldY_AfterUpdate()
MsgBox Me.FormFieldY
End Sub
If you want the parentheses stored as part of FormFieldY's value, perhaps you would get more joy by using an input mask rather than a format. With Access 2003, I used this as my text box control's input mask:
!\(999") "000\-0000;0;_
But it's probably easiest to use the Input Mask Wizard (click the button with 3 dots, which is just to the right of the Input Mask line on your control's property sheet). Choose phone number on the first wizard page. On the Wizard page which asks "How do you want to store the data?", select the "With the symbols in the mask" radio button.
Comment from djna: That was the solution, the expression change below seems not to be needed
The other issue is your DCount expression:
DCount("*","TableX","[MyColumn] = [FormFieldY] " ) > 0
I think you should use the value of FormFieldY rather than the name of the control. That may not be clear, so here's what I mean:
DCount("*","TableX","[MyColumn] = '" & Me.FormFieldY & "'" ) > 0