Counting records in a subform HELP!

JBurlison

Registered User.
Local time
Today, 19:13
Joined
Mar 14, 2008
Messages
172
i have a subform that is filtered by the key of the main form. i want to count how many items are in the subform


i tried this but it says i cannot use ".RecordCount = CountR" as read only

Code:
    On Error GoTo ErrorH
    Dim db As Database
    Dim rs As Recordset
    Dim PKey As String
    Dim CountR As Integer
    DoCmd.GoToRecord

PKey = Me.Product_Key

    Set db = CurrentDb
    Set rs = db.OpenRecordset("SELECT * FROM [ProductKeysAsigned] WHERE [Product Key] = PKey", dbOpenDynaset)
    
    With rs
        .MoveLast
        .MoveFirst
        .RecordCount = CountR
    End With
    rs.Close
    
    Me.Keys_Used = CountR
        GoTo EndH
ErrorH:
    Call ErrorRPT1
EndH:
 
CountR = .RecordCount

You're trying to assign a value to RecordCount, and you can't.
 
o lol duh why did i not see that
 
Probably because you get in a habit with a With statement of doing:

.Blah
.Blah
.Blah
.Blah
.Blah

etc. :P
 
Err now im getting too few parameters on

Code:
    Set rs = db.OpenRecordset("SELECT * FROM [ProductKeysAsigned] WHERE [Product Key] = PKey", dbOpenDynaset)

is this wrong im bad at SQL lol
 
Set rs = db.OpenRecordset("SELECT * FROM [ProductKeysAsigned] WHERE [Product Key] ='" & PKey & "'", dbOpenDynaset)
 
Just remember when you are referring to a control, a form, a variable, etc. you need to refer to it outside of the quotes, so you have to concatenate it in. Also, remember if dealing with text, encapsulate it with quotes and if it is a date encapsulate with # and if number it doesn't get either.
 

Users who are viewing this thread

Back
Top Bottom