Hi,
I am new to using VBA, and have been working with DAO Recordsets. I'm working on a little problem, and think that DAO Recordsets are the solution. I've been playing around with them to try and get it working, and have the following code, which works perfectly:
What I want to do now, is to pass in a variable value, rather than coding the CourseCode. I thought (in my ignorance) that declaring something like Function ReadCourseConte nt(strCourseCod e) would allow me to pass a course code into the function, and that I could use this in place of the string 'BW310_74' - something like this:
However, this fails, telling me I have a missing operator in the expression, and in VBE, the last line of code above is highlighted yellow, telling me strCourseCode=E mpty.
Is there a way to pass a variable into the FindFirst and FindNext methods of the DAO Recordset?
Cheers
I am new to using VBA, and have been working with DAO Recordsets. I'm working on a little problem, and think that DAO Recordsets are the solution. I've been playing around with them to try and get it working, and have the following code, which works perfectly:
Code:
Function ReadCourseContent()
Dim db As DAO.Database
Dim rst As DAO.Recordset
Set db = CurrentDb()
Set rst = CurrentDb.OpenRecordset("CourseContent", dbOpenSnapshot)
rst.FindFirst "[CourseCode] = 'BW310_74'"
Do While Not rst.NoMatch
Debug.Print rst!UnitNr, rst!Unit, rst!Content
rst.FindNext "[CourseCode] = 'BW310_74'"
Loop
rst.Close
Set rst = Nothing
db.Close
Set db = Nothing
SendKeys "^g"
End Function
Code:
Function ReadCourseContent(strCourseCode)
Dim db As DAO.Database
Dim rst As DAO.Recordset
Set db = CurrentDb()
Set rst = CurrentDb.OpenRecordset("CourseContent", dbOpenSnapshot)
rst.FindFirst "[CourseCode] = " & strCourseCode
Is there a way to pass a variable into the FindFirst and FindNext methods of the DAO Recordset?
Cheers
Comment