I have the error #Name? in a form in Access 2013 in a textbox that have as origin a DlookUp function.
Specifically I need to do the same thing that is on this topic: automatically update the field Costo Unitario field based on the selection of the field Operatore
The combobox of the Operatore field takes the values from a table named Operatori that it is like that:
Operatore CostoOp_Unitario
--------- --------
Marco 20,07
Giuseppe 20,02
Gennaro 19,69
Pierangelo 17,05
The function that is set up as Control Source for the textbox that gives the #Name? error is:
=DLookUp([CostoOp_Unitario];[Operatori];"[Operatore]=""" & [OperatoreComboBox].[Text] & """")
based on the function that is present in the thread that I linked above. OperatoreComboBox is the combobox Operatore in the image. Why it outputs this error?
I think your syntax is not correct. Try this one:
=DLookUp("[CostoOp_Unitario]","Operatori","[Operatore] = '" & [OperatoreComboBox] & "'")
Related
I'm trying to create a simple form using unbound combo boxes and a button that updates a table when clicked. I have already created another form that is similar to this that works great, so I tried to replicate it using the appropriate fields, but I get an error message- Run-time error '3061: Too few parameters. Expected 1.
The only two fields on the form are FrameID and FrameLocation and the button is MoveFrame. The table to be updated is StockFrames.
This is the code I have on the on-click event on the button:
Private Sub MoveFrame_Click()
CurrentDb.Execute "UPDATE StockFrames SET frameLocation = " & Me.frameLocation & _" WHERE FrameID = " & Me.FrameID
Me.frameLocation.Value = Null
Me.FrameID.Value = Null
End Sub
I appreciate any help anyone can offer. I'm very new to MS Access. If there is any other information that you need as far as the property settings, please let me know. I'm eager to learn and to get this form working properly.
Thank you.
If frameLocation is a text field, parameter needs apostrophe delimiters:
='" & Me.frameLocation & "' WHERE.
Remove that underscore character.
Date/Time fields use # delimiter.
I need to add some VBA code to a checkbox located on a subform of my front end Access 2016 database.
The goal is to insert to a table the value contained in a textbox located in the main form.
So far, the steps I took are:
Click on the checkbox located on the subform;
Create a temporary variable;
Insert the temporary variable into the related table;
Move on to the next item.
The code is the following:
Option Compare Database
Private Sub AssegnatoCampione_Click()
'Create temporary variable and store the selected value
TempVars("NumeroCampione").Value = Forms!FormCampioni2.SampleNo.Value
'Write the value in the database
CurrentDb.Execute " INSERT INTO DB_Offerte2017 " _
& "([NumeroCampione]) VALUES " _
& "(" & TempVars![NumeroCampione] & ")" ', dbFailOnError
End Sub
The error I get is: .
"Too few parameters. Expected 1."
Is there a way to know whether the variable is stored correctly or not?
Thank you so much for your help.
Edit 1:
Ok, so i guess that the error was due to DB_Offerte2017([NumeroCampione]) being a text field. I corrected the code in this way:
CurrentDb.Execute "INSERT INTO DB_Offerte2017 ( NumeroCampione ) VALUES ('" & Me.Parent.SampleNo & "')", dbFailOnError
This way, every time I click on the check box, a new record is added in the table "DB_Offerte2017", under the field "NumeroCampione".
However, I need to add those records to the same row where the checkboxes is located (e.g. Click on checkbox where ID = 2438 -> Add "SampleNo" value on DB_Offerte2017.NumeroCampione where ID = 2438).
Is it possible to add a where statement in the code?
Why not just a normal VBA variable or just reference the control? Code is behind subform and field/control on main form? Try:
CurrentDb.Execute "INSERT INTO DB_Offerte2017([NumeroCampione]) VALUES (" & Me.Parent.SampleNo & ")", dbFailOnError.
I am new to Access and also to VB. I have a report that displays information on transformers, the report displays data from a query that queries data from two different tables. I would like to use a button to open a PDF document saved in one of the tables.
The code I have so far is this:
Private Sub Command70_Click()
Dim hypa As String
hypa = DLookup("[TestReport]", "TransformerPics", "TxID = " & [Reports]![TransformerInfoSheet]!TXID)
Application.FollowHyperlink [hypa]
End Sub
The error i get is Run-time error '2471' The expression you have entered as a parameter produced this error: 'TP00686'
TP00686 is the transformer number that is displayed on the report.
You need to have some quotes in there:
hypa = DLookup("[TestReport]", "TransformerPics", "TxID = '" & [Reports]![TransformerInfoSheet]!TXID & "'")
Please also see:
DLookup Usage Samples
Dlookup using a string variable as criteria parameter
I can't for the life of me work out what is wrong with this, but I'm not an Access/VBA developer normally..
I have a database table with about 20 fields, one of which is a Yes/No field. I want to extract the Yes/No value using DLookup, however am receiving the following error:
Run-time error '3075':
Syntax error (missing operator) in query expression 'Enabled'.
The code I am using it:
MsgBox (DLookup("Enabled", "Numbers", "ID = " & Me.cbxNumber.Value & ""))
Enabled is a Yes/No field
ID is a String field.
The above DLookup works absolutely fine for returning String values for other fields, so the last parameter with the search query, and the table field, should be fine. It is simply complaining about the return field ('Enabled') thinking it is a query.
The MsgBox element is also irrelevant, as I have tried assigning the result to an Integer and to a Boolean, and it's not complaining of a type mismatch which I would expect if this were the problematic part.
Any thoughts?
You stated that ID is a string field. If that is the case, try changing the DLookup to...
DLookup("[Enabled]", "Numbers", "ID = " & Chr(34) & Me.cbxNumber.Value & Chr(34))
If ID is a Long, then use this string...
DLookup("[Enabled]", "Numbers", "ID = " & Me.cbxNumber.Value)
Your code works fine for me:
Table:
Form:
Code:
Private Sub Command30_Click()
MsgBox (DLookup("Enabled", "Numbers", "ID = " & Me.cbxNumber.Value & ""))
End Sub
The messagebox displays 0 or -1 as required. Things to check:
Is your code in the forms module? Otherwise Me.cbxNumber.Value won't return anything.
What do you get if you run
debug.print Me.cbxNumber
from the OnClick of a button on the form?
I have a single form on which there exists several combo boxes and text box. one combo box value (for the Wells) will be filled independently, then I needs the text box to have its value based on the value of the wells combo box value. I have created a query that solved the propblem partially, it requires parameter which the wells combo box value. If I ran with query a part from the form, it wroks good and asks for the parameter and it is OK. I do think to make use of VBA, adding a code which process a SELECT statement (of the query mentioned above), then to tell it to take its parameter from the wells combo value which will ready on the form.
Can someone help on this. Can this works as I descriped.
Thanks in advance.
Mohamed
Further to my question above, I have tried the following solution:
Private Sub Well_ID_Change()
Last_Ref.ControlSource = " SELECT TOP1 New_Ref FROM" & _
" BSW_Transactions WHERE BSW_Transactions.New_Ref Is Not Null AND BSW_Transactions.Well_ID = " & Me.Well_ID.Value & _
" ORDER BY BSW_Transactions.Sample_Date DESC"
End Sub
the Last_Ref is the text box I want to fill in with result of the embedded SELECT statement in the code. The Well_ID is the combo box which value will be the parameter of the SELECT statement. The Well_ID is number field and it displays the well_name and stores the associated ID value in the table. Upon running the form after saving changes, the Last_Ref text box showed (#Name?). I guessed that the text box (is a number field) found a text in the combo box Well_ID, so I added ".Value" to the above syntax at the criteria Me.Well_ID. However the problem still exists.
May I mistaken in the syntax, would someone help on this. Can this works fine?
Thanks in advance. Mohamed
The problem is that text boxes cannot have their control source set like a combo box or a list box, it needs to be passed the value e.g:
Private Sub Well_ID_Change()
Dim rs As Recordset
Set rs = CurrentDb.OpenRecordset("SELECT TOP1 [New_Ref] FROM" & _
" [BSW_Transactions] WHERE [BSW_Transactions].[New_Ref] Is Not Null" & _
" AND [BSW_Transactions].[Well_ID] = " & Me.Well_ID & _
" ORDER BY [BSW_Transactions].[Sample_Date] DESC", dbOpenSnapShot)
rs.MoveFirst
Last_Ref = rs![New_Ref]
rs.Close
Set rs = Nothing
End Sub
I've also dropped the .Value again from your combo box as its not required