Too few Parameters

Howlsta

Vampire Slayer
Local time
Today, 04:05
Joined
Jul 18, 2001
Messages
180
When I press the command button on my form i get the following error:

too few parameters, expected two.

But both the combo boxes for module and student are filled (I assume they are the parameters), so i can't understand why this happens. Any ideas anybody?
I've included the code below
If i put the cursor over rstStudentMod it comes up rstStudentMod = nothing - which sounds like there may be something wrong!

Private Sub cmdAdd_click()
Dim db As Database
Dim rstStudentMod As Recordset

If IsNull(Me.cboStudent) Or _
IsNull(Me.CboModule) Then

MsgBox "A module and student must be selected"

Else

Set db = CurrentDb()
Set rstStudentMod = db.OpenRecordset("qryPutStudentonModule", _
dbOpenDynaset)
With rstStudentMod
.AddNew
!StudentID = Me!cboStudent
!ModuleCode = Me!CboModule
.Update

End With
Me!CboModule = rstStudentMod!ModuleCode

End If
End Sub
 
Thanks for that. I've got a problem now with using the .Parameters collection.

I get an error saying: Method or data member not found.
The same think has been occurring when i try and use the LastModified code. Would this have anything to do with my references? I've got the DAO 3.6 Library ticked which I thought would get rid of that problem.
Any ideas pls?
 
It's still giving me the same error about the parameters. I think i've obviously gotta change some of the code further down based on what you've just told me. Call me a retard but I've only just started trying stuff with recordsets and haven't used code that much, so guess i need to go back to the books. The current code is below, if you can spot what i've done wrong.

Private Sub cmdAdd_click()
Dim rstStudentMod As Recordset
Dim db As DAO.Database
Dim rs As DAO.Recordset
Dim qd As DAO.QueryDef
Dim prm As DAO.Parameter

If IsNull(Me.cboStudent) Or _
IsNull(Me.CboModule) Then

MsgBox "A module and student must be selected"

Else

Set db = CurrentDb()
Set rstStudentMod = db.QueryDefs!qryPutStudentonModule
rstStudentMod.Parameters![Module] = Me.CboModule
rstStudentMod.Parameters![Student] = Me.cboStudent
rstStudentMod.OpenRecordset
With rstStudentMod
.AddNew
!StudentID = [Module]
!ModuleCode = [Student]
.Update

End With


End If
End Sub
 
Ok, when I click the cmd now, I get a message saying invalid use of property for the rstStudentMod variable. If Pat or anyone else can help I would be grateful. I've put **'s to indicate where the error occurs.

Private Sub cmdAdd_click()
Dim rstStudentMod As Recordset
Dim db As DAO.Database
Dim rs As DAO.Recordset
Dim qd As DAO.QueryDef
Dim prm As DAO.Parameter

If IsNull(Me.cboStudent) Or _
IsNull(Me.CboModule) Then

MsgBox "A module and student must be selected"

Else

Set db = CurrentDb()
Set qd = db.QueryDefs!qryPutStudentonModule
qd.Parameters![Module] = Me.CboModule
qd.Parameters![Student]=Me.cboStudent
** rstStudentMod = qd.OpenRecordset
With rstStudentMod
.AddNew
!StudentID = [Module]
!ModuleCode = [Student]
.Update

End With


End If
End Sub
 

Users who are viewing this thread

Back
Top Bottom