swaybright
Technical User
I am trying to create a way for users to fill a number of default records in a subform at the click of a button. the form is structured with subforms 3 layers deep (form-->subform1-->subform2-->subform3). Subform3 is the one I want to have the button fill. My approach is to have a button that when the users click it, an append query is run that places the records with the appropriate foreign key into the data table for subform3 record source. However, I only want the button to be available if there are no records in the data table having the foreign key (otherwise, the append will place a lot of unnecessary records if a user gets click happy ). So for the subform on current event, I have the following code (with the idea being to set the button visible property to false if icount>0):
Private Sub Form_Current()
Dim rs As Recordset
Dim db As Database
Dim icount As Integer
Dim iID As Long
iID = Forms!frmSample!frmNMRSample!frmNMRResults.Form.NMRResultsID
Debug.Print iID
Set db = CurrentDb
Set rs = db.OpenRecordset("qryNMRfill")
icount = rs.RecordCount
Debug.Print icount
End Sub
The qry sql statement is
SELECT Count(tblNMRResultDetails.NMRResultDetailsID) AS Total
FROM tblNMRResultDetails
WHERE (((tblNMRResultDetails.NMRResultsID)=[forms]![frmSample]![frmNMRSample]![frmnmrresults].[form]![nmrresultsid]));
The iID returns the expected value in the immediate window. When I run the query on its own with the form open, I get the expected recordset. However when I set the recordset, I get the too few parameters expected 1 error, it seems I cannot pass the value to the query. Any thoughts?
Thanks,
SW
Private Sub Form_Current()
Dim rs As Recordset
Dim db As Database
Dim icount As Integer
Dim iID As Long
iID = Forms!frmSample!frmNMRSample!frmNMRResults.Form.NMRResultsID
Debug.Print iID
Set db = CurrentDb
Set rs = db.OpenRecordset("qryNMRfill")
icount = rs.RecordCount
Debug.Print icount
End Sub
The qry sql statement is
SELECT Count(tblNMRResultDetails.NMRResultDetailsID) AS Total
FROM tblNMRResultDetails
WHERE (((tblNMRResultDetails.NMRResultsID)=[forms]![frmSample]![frmNMRSample]![frmnmrresults].[form]![nmrresultsid]));
The iID returns the expected value in the immediate window. When I run the query on its own with the form open, I get the expected recordset. However when I set the recordset, I get the too few parameters expected 1 error, it seems I cannot pass the value to the query. Any thoughts?
Thanks,
SW