Keith
Registered User.
- Local time
- Today, 09:25
- Joined
- May 21, 2000
- Messages
- 129
I am not trying to do anything specific but trying to learn more about Vb.
I have learned much from this Forum but I am now stuck.
I have a select query that gets all the customers from the customers table with the first letter begining with the letter "B" this is the SQL view:-
SELECT tblCustomer.LastName
FROM tblCustomer
WHERE (((Left([LastName],1))="B"));
My problem comes when I try to do this in code. My code is:-
Dim strSql As String
Dim rst As Recordset
Dim ing As Integer
strSql = " SELECT tblCustomer.LastName FROM tblCustomer WHERE ((Left([LastName],1)="B"))"
Set db = CurrentDb
Set rst = db.OpenRecordset(strSql)
rst.MoveFirst
rst.MoveLast
ing = rst.RecordCount
Me.txtResult = ing
End Sub
The code works without the WHERE clause but with it I get the following error,
"Compile Error Expected: end of statement" and the letter "B" is highlighted in the strSql.
I have searched this forum untill my eyes ache without any clues as to what I am doing wrong, admittedly I might be getting a bit senile. I would apreciate your help.
Keith.
I have learned much from this Forum but I am now stuck.
I have a select query that gets all the customers from the customers table with the first letter begining with the letter "B" this is the SQL view:-
SELECT tblCustomer.LastName
FROM tblCustomer
WHERE (((Left([LastName],1))="B"));
My problem comes when I try to do this in code. My code is:-
Dim strSql As String
Dim rst As Recordset
Dim ing As Integer
strSql = " SELECT tblCustomer.LastName FROM tblCustomer WHERE ((Left([LastName],1)="B"))"
Set db = CurrentDb
Set rst = db.OpenRecordset(strSql)
rst.MoveFirst
rst.MoveLast
ing = rst.RecordCount
Me.txtResult = ing
End Sub
The code works without the WHERE clause but with it I get the following error,
"Compile Error Expected: end of statement" and the letter "B" is highlighted in the strSql.
I have searched this forum untill my eyes ache without any clues as to what I am doing wrong, admittedly I might be getting a bit senile. I would apreciate your help.
Keith.