Trouble getting correct info on Subform

G

Guest

I created a table with 4 primary composite key. I created a form with a
combo box and several listboxes to update this table. This all works fine.
The table is like

tblName
ID autonumber
ActID PK
QualID PK
PracID PK
CatID PK
Required Yes/No
Enabled Yes/No

Now I created another form (form1) with a subform (form2) unbound just to
try to figure this out. On form1 I created 3 combo boxes and private
function and is called after all the combo boxes are not null. This function
updates the form2 with the correct amount of check boxes and labels
corresponding to the check boxes. Also, the check boxes are checked if
required and tells you whether it is enabled or not. Once again this works
fine. The problem I am having is I only want to show the ones that relate to
the 3 combo boxes. I tried using a query and as my recordset using this
query gives me an error stating too few paramters expexted 3. Here is my
function can someone point out what I am doing wrong? I commented out what I
thought I needed to do, but it didn't work. I have been coding for awhile,
but sometimes you get stuck and don't see what you might be doing wrong.

Private Function UpdateForm2()
Dim dbs As Database
Dim rst As Recordset
Dim strSelect As Recordset
Dim varX As Integer
Dim varC As Variant

Set dbs = CurrentDb

' Set strSelect = "SELECT * " & " FROM tblActQualPracCat " & " WHERE
(tblActQualPracCat.PracID= " & Me.cboPracticalName
' & " AND tblActQualPracCat.ActID = " & Me.cboActivityName & " And
tblActQualPracCat.QualID = " & Me.cboTypeOfQualification & ");"

Set rst = dbs.OpenRecordset("tblActQualPracCat")
If rst.RecordCount > 1 Then
varX = rst.RecordCount
Do
For k = 1 To varX
varC = DLookup("Category", "tblCategory", "CATID= " &
rst![CATID])
Forms!Form1.Form2.Form("chk" & k).Visible = True
Forms!Form1.Form2.Form("lbl" & k).Caption = varC
If rst![Required] = True Then
Forms!Form1.Form2.Form("chk" & k) = True
Else
Forms!Form1.Form2.Form("chk" & k) = False
End If
If rst![Enabled] = True Then
Forms!Form1.Form2.Form("chk" & k).Enabled = True
Else
Forms!Form1.Form2.Form("chk" & k).Enabled = False
End If
rst.MoveNext
Next k
Loop Until varX
End If
Forms!Form1.Form2.Form.Requery
End Function

Anyway thanks for any input.
 
G

Guest

Never mind I figured it out. What I did was create a temp table and then use
the code to update the fields on the subform. Here is my code. If someone
knows a better suggestion than what I am doing please let me know. The
subform has 20 check boxes and labels on it. I want them to populate and
show in order which correspond to the combo boxes on the main form. I don't
forsee them needing more than 10 at one time, but I built in some more just
in case, never know what they want after developing this.

Private Function UpdateForm2()
Dim dbs As Database
Dim rst As Recordset
Dim varX As Integer
Dim varC As Variant

DoCmd.SetWarnings False
DoCmd.OpenQuery "qrySetupFormTemp"
DoCmd.SetWarnings True

Set dbs = CurrentDb
Set rst = dbs.OpenRecordset("tblSetupTemp")

If rst.RecordCount >= 0 Then
varX = rst.RecordCount
Forms!Form1.Form2.Form.Refresh
For k = 1 To varX
varC = DLookup("Category", "tblCategory", "CATID= " &
rst![CATID])
Forms!Form1.Form2.Form("chk" & k).Visible = True
Forms!Form1.Form2.Form("lbl" & k).Caption = varC
If rst![Required] = True Then
Forms!Form1.Form2.Form("chk" & k) = True
Else
Forms!Form1.Form2.Form("chk" & k) = False
End If
If rst![Enabled] = True Then
Forms!Form1.Form2.Form("chk" & k).Enabled = True
Else
Forms!Form1.Form2.Form("chk" & k).Enabled = False
End If
rst.MoveNext
Next k
End If

For j = varX + 1 To 20
Forms!Form1.Form2.Form("lbl" & j).Caption = ""
Forms!Form1.Form2.Form("chk" & j).Visible = False

Next j
Forms!Form1.Form2.Form.Requery
End Function



Fysh said:
I created a table with 4 primary composite key. I created a form with a
combo box and several listboxes to update this table. This all works fine.
The table is like

tblName
ID autonumber
ActID PK
QualID PK
PracID PK
CatID PK
Required Yes/No
Enabled Yes/No

Now I created another form (form1) with a subform (form2) unbound just to
try to figure this out. On form1 I created 3 combo boxes and private
function and is called after all the combo boxes are not null. This function
updates the form2 with the correct amount of check boxes and labels
corresponding to the check boxes. Also, the check boxes are checked if
required and tells you whether it is enabled or not. Once again this works
fine. The problem I am having is I only want to show the ones that relate to
the 3 combo boxes. I tried using a query and as my recordset using this
query gives me an error stating too few paramters expexted 3. Here is my
function can someone point out what I am doing wrong? I commented out what I
thought I needed to do, but it didn't work. I have been coding for awhile,
but sometimes you get stuck and don't see what you might be doing wrong.

Private Function UpdateForm2()
Dim dbs As Database
Dim rst As Recordset
Dim strSelect As Recordset
Dim varX As Integer
Dim varC As Variant

Set dbs = CurrentDb

' Set strSelect = "SELECT * " & " FROM tblActQualPracCat " & " WHERE
(tblActQualPracCat.PracID= " & Me.cboPracticalName
' & " AND tblActQualPracCat.ActID = " & Me.cboActivityName & " And
tblActQualPracCat.QualID = " & Me.cboTypeOfQualification & ");"

Set rst = dbs.OpenRecordset("tblActQualPracCat")
If rst.RecordCount > 1 Then
varX = rst.RecordCount
Do
For k = 1 To varX
varC = DLookup("Category", "tblCategory", "CATID= " &
rst![CATID])
Forms!Form1.Form2.Form("chk" & k).Visible = True
Forms!Form1.Form2.Form("lbl" & k).Caption = varC
If rst![Required] = True Then
Forms!Form1.Form2.Form("chk" & k) = True
Else
Forms!Form1.Form2.Form("chk" & k) = False
End If
If rst![Enabled] = True Then
Forms!Form1.Form2.Form("chk" & k).Enabled = True
Else
Forms!Form1.Form2.Form("chk" & k).Enabled = False
End If
rst.MoveNext
Next k
Loop Until varX
End If
Forms!Form1.Form2.Form.Requery
End Function

Anyway thanks for any input.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top