Need a proof read!!

DaniBoy

Registered User.
Local time
Today, 08:02
Joined
Nov 18, 2001
Messages
174
Hello,
I have copy this code and modified it from the Northwind database. Its a code that looks up the value of the UnitPrice field from the Products Table and puts this value on the UnitPrice field on the Orders Subform. All I chnaged was the field name and the table name but I get this messege when I try it:

The expression you entered as a query parameter produced this Error: 'The object does'nt contain the Anomation object "Fri."

I looked at all the fields used om my database, and compare them with the Northwind, the only difference is that am using a text field instead of a Autonumber for ProductID, the rest is the same.

What do I need to change? I attached a copy of my DB so you can see my problem.




Private Sub ProductoID_AfterUpdate()
On Error GoTo Err_ProductoID_AfterUpdate

Dim Filter As Currency

' Evaluate filter before it's passed to DLookup function.
Filter = "ProductoID = " & Me!ProductoID

' Look up product's unit price and assign it to UnitPrice control.
Me!Precio = DLookup("Precio", "Productos", Filter)

Exit_ProductoID_AfterUpdate:
Exit Sub

Err_ProductoID_AfterUpdate:
MsgBox Err.Description
Resume Exit_ProductoID_AfterUpdate

End Sub
 

Attachments

Change the DLookup line to

Me!Precio = DLookup("Precio", "Productos", """ & Filter & """) 'As you are using txt for an ID (Not a good idea mind you)

Use an AutonumberID for the fields but use your current ID as a ProductCode. This will save a lot of potential headaches with duplication of primary keys etc....
 
Thanks Fizzio

Well you are right!! am going to change it back to Autonumber, the problem I have is that am not that good at coding so I struggle to do some codes. I actualy got a code from the forum on how to use the "Not on list" event so that when the user type PrimaryKey and its not on the list it would tell the user that its not on the list but it also will let the user add it to the list.
I never realy looked at how it worked, I knew it uses the primary key, But I just figured out thta if I change the field to what ever am using on my combobox!! So it workd good. Thanks for the push on Autonumbers!!!

DaniBoy

PS

Here is that code:
Private Sub Facturas_ClienteID_NotInList(NewData As String, Response As Integer)
Dim Result
Dim Msg As String
Dim CR As String

CR = Chr$(13)

' Exit this subroutine if the combo box was cleared.
If NewData = "" Then Exit Sub

' Ask the user if he or she wishes to add the new customer.
Msg = "'" & NewData & "' El Cliente No Exixte." & CR & CR
Msg = Msg & "Desea Agregarlo?"
If MsgBox(Msg, vbQuestion + vbYesNo) = vbYes Then
' If the user chose Yes, start the Customers form in data entry
' mode as a dialog form, passing the new company name in
' NewData to the OpenForm method's OpenArgs argument. The
' OpenArgs argument is used in Customer form's Form_Load event
' procedure.
DoCmd.OpenForm "Clientes", , , , acAdd, acDialog, NewData
End If

' Look for the customer the user created in the Customers form.
Result = DLookup("[The field you use]", "The Table", _
"[The Field you use]='" & NewData & "'")
If IsNull(Result) Then
' If the customer was not created, set the Response argument
' to suppress an error message and undo changes.
Response = acDataErrContinue
' Display a customized message.
MsgBox "Por Favor Trate de Nuevo!"
Else
' If the customer was created, set the Response argument to
' indicate that new data is being added.
Response = acDataErrAdded
End If
End Sub
 

Users who are viewing this thread

Back
Top Bottom