Adding two strings together

mbaue002

Registered User.
Local time
Today, 05:54
Joined
Mar 20, 2012
Messages
10
I am very new to VBA. I am trying to add the two statements below together and get a record count when the two criteria are met. I tried to use an if and statement, but had no luck. Does anyone have any suggestions on how to put these two statements together.

Dim db As DAO.Database
Set db = CurrentDb()
Dim rs1 As DAO.Recordset
Dim strInstrument As String
Dim sglCoupon As Single



sglCoupon = Me.LstCoupon
strSQL = "select Tbl4.* from Tbl4 WHERE Tbl4.[Open Amount] > 0 and Tbl4.[Coupon]=" & sglCoupon
Set rs1 = db.OpenRecordset(strSQL, dbOpenDynaset)

strInstrument = Me.LstInstrument
strSQL = "select Tbl4.* from Tbl4 WHERE Tbl4.[Open Amount] > 0 and Tbl4.[Instrument Name] = '" & strInstrument & "'"
Set rs1 = db.OpenRecordset(strSQL, dbOpenDynaset)
rs1.MoveLast
Debug.Print rs1.RecordCount
rs1.Close
Set rs1 = Nothing

Any help would be greatly appreciated.
 
Could you provide some sample input data and what data you expect your query(ies) to return based on that data?

How come you can't just merge the WHERE clauses of those two statements?
 
The data it will be returning for now is just a simple record count. I tried to merge them at the WHERE clause but got a 424 run time error. I figured I could do it either way, but couldnt get the syntax right to merge them at the WHERE clause.
 
Have you tried:
WHERE Tbl4.[Open Amount] > 0 and and Tbl4.[Coupon]=" & sglCoupon and Tbl4.[Instrument Name] = '" & strInstrument & "'"
 
Thanks for all the help guys, I got it working finally.
 

Users who are viewing this thread

Back
Top Bottom