Hi folks hope you can help,
The application I am trying to build is in tended to search the data base for all items associated with a particular course Elements Learning Outcomes etc, The application then outputs the data to a word document.
The code I am using is below (note that I have used message boxes to try and debug already and can see nothing wrong with the statements that they produce.
Access however keeps giving me a 3061 error - "Too Few parameters. Expected 1." at the first instance of rs.Openrecordset()
I have read a few other threads related to this but they focus on the SQL Statements that are used and as I have said using the Message boxes I can't really see a problem with them.
Any help is gratefully recieved
The Start of wisdom is to realise you know nothing. I'll be a genius then!
The application I am trying to build is in tended to search the data base for all items associated with a particular course Elements Learning Outcomes etc, The application then outputs the data to a word document.
The code I am using is below (note that I have used message boxes to try and debug already and can see nothing wrong with the statements that they produce.
Code:
Private Sub Sheets_Click()
Dim db As DAO.Database
Dim rs As DAO.Recordset
Dim i As Integer
Dim bcf1 As Variant
Dim bcf2 As Variant
Dim bcf3 As Variant
Dim arrVars As Variant
Dim sqlEL As String
Dim sqlLO As String
Dim sqlBcf1 As String
Dim sqlBcf2 As String
Dim sqlBcf3 As String
Dim ElLines As String
Dim ValLines As String
Dim LOLines As String
Dim bcfLines As String
Set db = CurrentDb()
'Delivering our Business
'Relationships with People
'Developing our Organisation
'define sql statements
sqlLO = "SELECT LOuts.LOId, LOuts.Name, LOuts.Content, LOuts.Validation FROM LOuts WHERE LOuts.Course_id=" & Me.Course_ID & " ORDER BY LOID;"
MsgBox sqlLO
sqlEL = "SELECT Element.El_Id,Element.Content FROM Element WHERE Element.Course_id ='" & Me.Course_ID & "' ORDER BY [EL_Id];"
MsgBox sqlEL
sqlBcf1 = "SELECT Bcf_info.Name, Bcf_Info.Content FROM Bcf_info, Link_Bcf WHERE Bcf_info.Bcf_Id= Link_Bcf.Bcf_Id AND Link_Bcf.Course_id='" & Me.Course_ID & "' AND Bcf_info='Delivering our Business' ORDER BY "
MsgBox sqlBcf1
sqlBcf2 = "SELECT Bcf_info.Name, Bcf_Info.Content FROM Bcf_info, Link_Bcf WHERE Bcf_info.Bcf_Id= Link_Bcf.Bcf_Id AND Link_Bcf.Course_id='" & Me.Course_ID & "' AND Bcf_info='Relationships with People' ORDER BY "
MsgBox sqlBcf2
sqlBcf3 = "SELECT Bcf_info.Name, Bcf_Info.Content FROM Bcf_info, Link_Bcf WHERE Bcf_info.Bcf_Id= Link_Bcf.Bcf_Id AND Link_Bcf.Course_id='" & Me.Course_ID & "' AND Bcf_info='Developing our Organisation' ORDER BY "
MsgBox sqlBcf3
' Retreive the Element Details / Format them - ELnumber. EL Content
Set rs = db.OpenRecordset(sqlEL)
arrVars = rs.GetRows(rs.RecordCount)
For i = 0 To rs.RecordCount - 1
ElLines = arrVars(0, i) & ". " & arrVars(1, i) & vbCrLf
Next i
'Retreive the LO Details / Format them thus -> LO Number. LO Name & VBcrlf & " " & LO Content
'Retreive the LO Validation Details / Format them thus -> LO Number. LO Validation
Set rs = db.OpenRecordset(sqlLO)
arrVars = rs.GetRows(rs.RecordCount)
For i = 0 To rs.RecordCount - 1
LOLines = arrVars(0, i) & ". " & arrVars(1, i) & " " & vbCrLf & " " & arrVars(2, i) & vbCrLf
ValLines = arrVars(0, i) & ". " & arrVars(1, i) & " " & vbCrLf & " " & arrVars(3, i) & vbCrLf
Next i
Set rs = db.OpenRecordset(sqlBcf1)
arrVars = rs.GetRows(rs.RecordCount)
For i = 0 To rs.RecordCount
bcf1(0, i) = arrVars(0, i)
bcf1(1, i) = arrVars(1, i)
Next i
Set rs = db.OpenRecordset(sqlBcf2)
arrVars = rs.GetRows(rs.RecordCount)
For i = 0 To rs.RecordCount - 1
bcf2(0, i) = arrVars(0, i)
bcf2(1, i) = arrVars(1, i)
Next i
Set rs = db.OpenRecordset(sqlBcf3)
arrVars = rs.GetRows(rs.RecordCount)
For i = 0 To rs.RecordCount - 1
bcf3(0, i) = arrVars(0, i)
bcf3(1, i) = arrVars(1, i)
Next i
Dim Wrd As Word.Application
Set Wrd = CreateObject("Word.Application")
Wrd.Documents.Add "D:\PACK.dot"
Wrd.Visible = True
'Populate Training Pack Template for this course
With Wrd.ActiveDocument.Bookmarks
.Item("Aim").range.Text = Me.Aim
.Item("ELEMENTS").range.Text = ElLines
.Item("LEARNINGOUTCOMES").range.Text = LOLines
.Item("LOvals").range.Text = ValLines
.Item("Resources").range.Text = Me.resources
.Item("Duration").range.Text = Me.Duration
.Item("CourseVal").range.Text = Me.Validation
.Item("TITLE").range.Text = Me.Name
.Item("AIM").range.Text = Me.Aim
.Item("GROUP").range.Text = Me.Target_Group
'Populate BCF details
' Deliver our Business section
If Not IsNull(bcf1(0, 0)) Then
.Item("BCF1TITLE").range.Text = bcf1(0, 0)
.Item("BCF1TXT").range.Text = bcf1(1, 0)
End If
If Not IsNull(bcf1(0, 1)) Then
.Item("BCF2TITLE").range.Text = bcf1(0, 1)
.Item("BCF2TXT").range.Text = bcf1(1, 1)
End If
If Not IsNull(bcf1(0, 2)) Then
.Item("BCF3TITLE").range.Text = bcf1(0, 2)
.Item("BCF3TXT").range.Text = bcf1(1, 2)
End If
If Not IsNull(bcf1(0, 3)) Then
.Item("BCF4TITLE").range.Text = bcf1(0, 3)
.Item("BCF4TXT").range.Text = bcf1(1, 3)
End If
' Relationships with People
If Not IsNull(bcf2(0, 0)) Then
.Item("BCF5TITLE").range.Text = bcf2(0, 0)
.Item("BCF5TXT").range.Text = bcf2(1, 0)
End If
If Not IsNull(bcf2(0, 1)) Then
.Item("BCF6TITLE").range.Text = bcf2(0, 1)
.Item("BCF6TXT").range.Text = bcf2(1, 1)
End If
If Not IsNull(bcf2(0, 2)) Then
.Item("BCF7ITLE").range.Text = bcf2(0, 2)
.Item("BCF7TXT").range.Text = bcf2(1, 2)
End If
If Not IsNull(bcf2(0, 3)) Then
.Item("BCF8TITLE").range.Text = bcf2(0, 3)
.Item("BCF8TXT").range.Text = bcf2(1, 3)
End If
'Developing our Organisation
If Not IsNull(bcf3(0, 0)) Then
.Item("BCF9TITLE").range.Text = bcf3(0, 0)
.Item("BCF9TXT").range.Text = bcf3(1, 0)
End If
If Not IsNull(bcf3(0, 1)) Then
.Item("BCF10TITLE").range.Text = bcf3(0, 1)
.Item("BCF10TXT").range.Text = bcf3(1, 1)
End If
If Not IsNull(bcf3(0, 2)) Then
.Item("BCF11TITLE").range.Text = bcf3(0, 2)
.Item("BCF11TXT").range.Text = bcf3(1, 2)
End If
If Not IsNull(bcf3(0, 3)) Then
.Item("BCF12TITLE").range.Text = bcf3(0, 3)
.Item("BCF12TXT").range.Text = bcf3(1, 3)
End If
End With
'Wrd.ActiveDocument.PrintOut
Wrd.ActiveDocument.close (wdDoNotSaveChanges)
Wrd.Quit
End Sub
Access however keeps giving me a 3061 error - "Too Few parameters. Expected 1." at the first instance of rs.Openrecordset()
I have read a few other threads related to this but they focus on the SQL Statements that are used and as I have said using the Message boxes I can't really see a problem with them.
Any help is gratefully recieved
The Start of wisdom is to realise you know nothing. I'll be a genius then!