Need Help With A SQL Statement

D

David

I have got the following SQL Statement to populate a record, but it will
only populate 1 box on all off the records in continuios form mode, the rest
of the boxes say "name?"
Is there a way to correct the statement so that it populates the entire
record in each continuios form.

And is there a way to sort this list ascending?

Dim strSQL As String
If Me.Check22 = True Then
strSQL = "SELECT vehinfo.Vehicle FROM vehinfo " & _ "WHERE vehicle Not Like
'old*';"
Else
strSQL = "SELECT vehinfo.vehicle FROM vehinfo;"
End If

With [Forms]![setveh]
.RecordSource = strSQL
.Requery
End With
End Sub

Thanks
David
 
K

Kelvin

David,

Your SQL statement only returns one value vehinfo.Vehicle so this is the
only text box that will be populated when you run the command. If you are
trying to populate every item on the form you need to include the other
fields as well. You can include all fields using the *.

If Me.Check22 = True Then
strSQL = "SELECT vehinfo.* FROM vehinfo " & _ "WHERE (vehinfo.vehicle Not
Like 'old*');"
Else
strSQL = "SELECT vehinfo.* FROM vehinfo;"
End If

Kelvin
 
D

David

Kelvin,
That worked, but I still have the issue with sorting the form, is there a
way through code to sort the SQL return?

Thanks
David
 
K

Kelvin

If Me.Check22 = True Then
strSQL = "SELECT vehinfo.* FROM vehinfo WHERE (vehinfo.vehicle Not Like
'old*') ORDER BY vehInfo.vehicle;"
Else
strSQL = "SELECT vehinfo.* FROM vehinfo ORDER BY vehInfo.vehicle;"
End If

Change vehicle to the field you want to sort by.

Kelvin
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top