count records in search from (1 Viewer)

Gasman

Enthusiastic Amateur
Local time
Today, 06:03
Joined
Sep 21, 2011
Messages
14,317
JHB provided you with a solution.

The control for Lab A LCD is populated by this code
Code:
  Set rst = dbs.OpenRecordset("SELECT SchoolName, Lab, device, Kind " _
  & "FROM SchoolNameTbl INNER JOIN DevicesTbl ON SchoolNameTbl.ID = DevicesTbl.ID " _
  & "WHERE [SchoolName]like '*" & Me.Text0.Text & "*' " _
  & "AND Lab='Lab-A' AND Device='LCD'")
  If Not rst.EOF Then
    rst.MoveLast
    Me.FrmHlp.Form!CountLCDLabA = rst.RecordCount
  End If

however once set it is not cleared, that is why you see 3, that is left over from a previous search.
So set each control to 0 before issuing the sql for the recordset.

Code:
  [B]Me.FrmHlp.Form!CountLCDLabA = 0[/B]
  Set rst = dbs.OpenRecordset("SELECT SchoolName, Lab, device, Kind " _
  & "FROM SchoolNameTbl INNER JOIN DevicesTbl ON SchoolNameTbl.ID = DevicesTbl.ID " _
  & "WHERE [SchoolName]like '*" & Me.Text0.Text & "*' " _
  & "AND Lab='Lab-A' AND Device='LCD'")
  If Not rst.EOF Then
    rst.MoveLast
    Me.FrmHlp.Form!CountLCDLabA = rst.RecordCount
  End If
Use the same logic for the other controls.
 
Last edited:

mohamedmatter

Registered User.
Local time
Yesterday, 22:03
Joined
Oct 25, 2015
Messages
112
JHB provided you with a solution.

The control for Lab A LCD is populated by this code
Code:
  Set rst = dbs.OpenRecordset("SELECT SchoolName, Lab, device, Kind " _
  & "FROM SchoolNameTbl INNER JOIN DevicesTbl ON SchoolNameTbl.ID = DevicesTbl.ID " _
  & "WHERE [SchoolName]like '*" & Me.Text0.Text & "*' " _
  & "AND Lab='Lab-A' AND Device='LCD'")
  If Not rst.EOF Then
    rst.MoveLast
    Me.FrmHlp.Form!CountLCDLabA = rst.RecordCount
  End If

however once set it is not cleared, that is why you see 3, that is left over from a previous search.
So set each control to 0 before issuing the sql for the recordset.

Code:
  [B]Me.FrmHlp.Form!CountLCDLabA = 0[/B]
  Set rst = dbs.OpenRecordset("SELECT SchoolName, Lab, device, Kind " _
  & "FROM SchoolNameTbl INNER JOIN DevicesTbl ON SchoolNameTbl.ID = DevicesTbl.ID " _
  & "WHERE [SchoolName]like '*" & Me.Text0.Text & "*' " _
  & "AND Lab='Lab-A' AND Device='LCD'")
  If Not rst.EOF Then
    rst.MoveLast
    Me.FrmHlp.Form!CountLCDLabA = rst.RecordCount
  End If
Use the same logic for the other controls.
Thank you very much. Is it advice on the name of a book to learn how to write vba codes. as I did
 

Users who are viewing this thread

Top Bottom