Using SQL Query to fill in field in Form

Dylan Snyder

Registered User.
Local time
Today, 07:52
Joined
Dec 31, 2007
Messages
89
I want to set the "Fee" Field on a form to the penalty value in the Penalty table where Penalty = "Non-Compliant Docs" This is what I came up with but it keeps telling me there is an error in the From clause. This is my first time using SQL on Forms. Any glaring flaws. Would this even work?

Dim strSQL As String

strSQL = "SELECT Penalties.[Penalty Value]" & _
"FROM Penalties" & _
"WHERE (((Penalties.Penalty)='Non-Compliant Docs'));"

DoCmd.RunSQL strSQL
Me.Fee = strSQL
 
You can actually put the dlookup (prefixed with an equal sign) in the default value of the field on the form.
=DLOOKUP("Penalty Value","Penalties","'Penalty = 'Non-Compliant Docs'")
 
Thanks,
That worked like a champ. Am I right in assuming that Dlookup can only lookup the value in a table and not preform a query? Even so, this is a cool tool to have. Thanks
 
It can access a query (prewritten of course) as well as a table. You can not specify SQL in the dlookup function.
 

Users who are viewing this thread

Back
Top Bottom