I have a DLookup function for displaying records from another table. Function works o.k., but problem occurs when there is empty field in the parent record.
Here is my DLookup function :
=DLookUp("Surname";"Employees";"ID_Employees_Table2=" & [Forms]![Company]![Company_Subform].[Form]![ID_Employees_Table1])
So, this works when ID_Employees_Table1 field is not empty, but If is "empty" It returns me #Error.
I tried with Nz function like this :
=Nz(DLookUp("Surname";"Employees";"ID_Employees_Table2=" & [Forms]![Company]![Company_Subform].[Form]![ID_Employees_Table1]);0)
But Access still returns me #Error in Textbox - where I'm using this function. I've tried also in combination with IsNull, IIf, but both can't stop this #Error from appearing.
How on earth can I stop this error from appearing in my Textbox, please any advices !
Answer is -
=DLookUp("Surname";"Employees";"ID_Employees_Table2=" & Nz([Forms]![Company]![Company_Subform].[Form]![ID_Employees_Table1]);0))
I just had to put Nz function in correct place, nightmare !!
Related
I am trying to filter a subform with a textbox.
I have a query to show table records in the subform and I have the criteria to filter the table, but when I type in the textbox to filter the sub form it only shows me one record with that name. I need it to show me all the names.
The criteria for my query is below.
Like "*" & [Forms]![frmPlanningForecast]![FETextbox].[Text] & "*"
I then have an OnChange event on the textbox to requery the subform.
As mentioned above I need it to show me all the records matching what i have typed, not just one.
When I use the filter option within the table itself(Dropdown box on the field header) and select the filter from there, it works great. But I need it to be typed into a textbox.
The picture attached will show you what I mean, I have "EQ" typed in the text box but it has only returned 1 record when their are 15 called "EQ" on the table.
First of all add single quotes around Like parameter:
Like "'*" & [Forms]![frmPlanningForecast]![FETextbox] & "*'"
and second - Access has an old bug: if you refer in the query to form field like you did, it doesn't renew the value, used for criteria during Requery, you always will receive the same results. Workaround - replace reference to field by global function, which returns textbox value or use dynamic generating of RecordSource for subform.
Global function example:
Public Function GetFE() As Variable
GetFE = [Forms]![frmPlanningForecast]![FETextbox]
End Function
Place it in any standard VBA module. Then your Like will look like this:
Like "'*" & GetFE() & "*'"
I found an easier method and just wanted to let others know.
Instead of using criteria I used the following vba code.
DoCmd.ApplyFilter , (FETextbox = qryPlannedHours.LeadFE), SubFormPF
In older versions of Access, didn't there used to be an option in the query to use the sum field something like this:
[Formnane].[TextField]
I know that's very simplistic and I don't fully recall how to use it but it was something like that, simple and straight forward if you're not a VB user. Forgive my lack of conviction, I've used it before but it was 20 years ago.
I have a frmA, based on qryA.
Button btnOpenfrmB on frmA opens another frmB, based on qryB.
But this frmB includes some unbound textboxes, with data from qryC, i.e.
=DLookUp("Field";"[qryC]";"[ValueC] = " & [ValueB]). If qryB has no data (records), Dlookup fields return errors and opening frmB, which includes these textboxes, ends with an error. I understand this behaviour of frmB (there is no value B, that's why an error), but HOW CAN I AVOID IT and correctly open frmB for entering the first record ? When qryB has at least one record, everything works OK.
Thanx in advance
Duski.
Just use Nz function if Field don't have, for instance 0 values:
=DLookUp("Field";"[qryC]";"[ValueC] = " & Nz([ValueB],0))
or iif function if Field can contain any value:
=iif(IsNull([ValueB]),"",DLookUp("Field";"[qryC]";"[ValueC] = " & [ValueB]))
I have a form, and am counting the number of records in a subform. Sometimes the subform is empty, which I'd like to check for, but it throws
Run-time error '2427': You entered an expression that has no value
It's obvious why this error is happening, but less obvious is how to work around it. This is the code causing the error. MainTableComboBox.Value contains RecordID.
DCount("*", "[SubFormTable]", "[SubFormTable].[RecordID] = " & MainTableTextBox.Value)
I've tried the following but it still errors out.
Using If(IsError(Dcount...)) then (do stuff)
Checking that the number of records is larger than zero
Nested Nothing, IfNull, and IfEmpty statements
Using an error handler
What other ways exist to get around this error?
I think you could set a recordset equal to the subform datasource and use IF rs.EOF = True Then to see if there are records to show before running your dcount function. See this question for more information.
I'm working on a little project in Access using VBA. I created a report with some data from three different tables. In the Report_Open method I want to assign a query to the ControlSource of a TextBox.
Here is my code
Me.textImpactP.ControlSource = DLookup("[ImpactText]", "Root_cause_basic_reports", "[Report_id] =" & rid & " And [Root_cause_basic_id] =" & rootCauseId)
When I run this I keep getting the dialog "Enter Parameter Value".
The parameter "people" is the result of my DLookup and is supposed to be the value of my TextBox on my report.
Does anyone have an idea how to get the parameter "people" as a value in my TextBox?
Enter Parameter value does not represent, what you think it does. It normally pops up when you try to open a Report whose record Source is based on a Query which requests a parameter. Check the Query again.
I'm building a relatively simple datasheet-style form for selecting a record (which will be used to populate another form)
The form pulls from a query with multiple columns. Since it's counter-intuitive to have a highlighted field and data entry cursor when all the user wants to do is select a record, I added the following code to each field on the form:
Private Sub Model_Enter()
RunCommand acCmdSelectRecord
End Sub
This works fine for the "Model" field, but for every other field it gives me the following error:
Run-time error 3125
" is not a valid name. Make sure that it does not include invalid characters or punctuation and that it is not too long.
There's literally nothing else going on in this form, so I have no idea what the issue is, or why the code works for Model and breaks for everything else. Anyone else run into this issue?
I suggest you use the On Current event, rather than write code for each control. It is also possible to use conditional formatting and a little code to highlight a record.