Add subform record count to text box?

uscarioca

New Member
Joined
Jul 7, 2004
Messages
16
Private Sub cmdSearch_Click()
Me.Refresh
Me.txtRegInfo = "Stores are in Region " & cmbRegion & " (" & cmbState & ")"
End Sub

Can someone help me understand how I can insert a record count variable from a subform qry? My qry populating my subform is called qryPL_Store_List. Lets say qryPL_Store_List has 37 records, I would want txtRegInfo = "37 Stores are in Region 26 (MO)".

Please note that I have got the cmbRegion and cmbState variables to work in the text box. I am stumped on the getting the record count.

Any help would be appreciated.
Thanks Chris
 

Excel Facts

Can a formula spear through sheets?
Use =SUM(January:December!E7) to sum E7 on all of the sheets from January through December
You can try something like this:

Code:
  Dim cnn As ADODB.Connection
  Dim rst As ADODB.Recordset
  Set cnn = CurrentProject.Connection
  Set rst = New ADODB.Recordset
  Dim recordCount As Long

  rst.Open Me.subform.Form.RecordSource, cnn
  While Not rst.EOF
    rst.MoveNext
    recordCount = recordCount + 1
  Wend
  rst.Close
  
  Me.txtRegInfo= recordCount & " Stores are in Region " & cmbRegion & " (" & cmbState & ")"

Replace 'subform' with the name of your subform.
 
Upvote 0

Forum statistics

Threads
1,223,247
Messages
6,171,007
Members
452,374
Latest member
keccles

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top