Quote:
> I'm new to VB, so I apologize if this is silly
> I set up a form to enter vehicle usage reports in a table.
> The form has a combo box that receives a list of vehicles from the vehicle
> table.
> When this vehicle is selected, I would like to enter some values in other
> textboxes automatically,
> I am using an SQL statement that works in a query, but I can't get it to
> enter what I want in the form "after update"
> this is the code:
> Private Sub VehicleID_AfterUpdate()
> Dim strSQL As String
> strSQL = "SELECT Max(Mileage.LOF) AS Expr1 FROM Mileage WHERE
> (((Mileage.[Vehicle ID])=[Forms]![Mileage]![VehicleID]));"
> LOF.Value = strSQL
> End Sub
> I also tried "LOF.defaultValue = strSQL"
> Does it matter that LOF is a number?
Have you tried making the query for the combo box control contain all of the
fields that you want to update on your form (you don't have to see them when
the combo box opens set the column lengths to 0") then defualt value of the
controls to the particular combo box column.
for example say query contains;
vehicle id; operator; beginning miles (dmax on vehicle table); modle; etc
in the after update code:
if vehicleId.column(2) <>"" then
me!operator = cboVehicleId.column(2)
else
me!operator = ""
end if
if VehicleId.column(3) <> "" then
me!milage = vehicleId.column(3)
else
me!milage = ""
end if
and so on.
obviously the if then parts would not be necessary if the particular field
is never empty
the combo box field count property must be set to the number of fields in
the query or else
the controls will appear blank.
this is for controls that can be changed by the user on the form if you
simply want to insert default values, if the values are just for info but
are not to be changed you don't need to write any code
just create an unbound text box on the form and set its control source to =
me!VehicleId.column(x)
is this of any help?