Problem with Sum in Textbox on a form in Subform (1 Viewer)

waseem0888

Member
Local time
Today, 06:14
Joined
Jul 25, 2020
Messages
46
I have one form named Charts_Dashboard there i have the textbox name txtUnder_Review so in my textbox Control Source I was summing values from one of the query names qryDateRange with the following expression =DSum("[Under Review]","qryDateRange") It works fine. But now i have one parent form named frmMain and on that form, i have tab control and the page is named as P3 and then on that page, i have a subform named frmChart and in this form source Object i am using Charts_Dashboard and i don't know how to refer theses forms in my textbox on charts_dashboard to sum values from the query i tried many expressions but didn't work.

Second problem is on the same form, i am selecting date ranges via 2 text boxes through the below code so after attaching to the subform i have the same issue to refer to the parent forms.

Sub genrateReport()
Dim dateCriteria, dateRange As String
Me.Refresh
If IsNull(Me.txtStartDate) Or IsNull(Me.txtEndDate) Then
MsgBox "Please Enter Date Range...", vbiformation, "Date Range Required"
Me.txtStartDate.SetFocus
Else
dateCriteria = "([Submitted_Date] >= #" & Me.txtStartDate & "# And [Submitted_Date] <= #" & Me.txtEndDate & "#)"
dateRange = "Select Submitted_Date form Charts_Dashboard"
DoCmd.ApplyFilter dateRange
End If
End Sub

now it's giving an error
Runtime Error: 2491 "The action or method is invalid because the form or report isn't bound to a table or query".
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 13:14
Joined
May 7, 2009
Messages
16,394
first question, the expression

=DSum("[Under Review]","qryDateRange")

will still work for your subform.

second, you need to specify the subform to "filter":


Sub genrateReport()
Dim dateCriteria, dateRange As String
Me.Refresh
If IsNull(Me.txtStartDate) Or IsNull(Me.txtEndDate) Then
MsgBox "Please Enter Date Range...", vbiformation, "Date Range Required"
Me.txtStartDate.SetFocus
Else
dateCriteria = "([Submitted_Date] >= #" & Me.txtStartDate & "# And [Submitted_Date] <= #" & Me.txtEndDate & "#)"
dateRange = "Select Submitted_Date form Charts_Dashboard"
DoCmd.ApplyFilter , dateCriteria, "yourSubformName"
End If
End Sub
 

waseem0888

Member
Local time
Today, 06:14
Joined
Jul 25, 2020
Messages
46
Hi, arnelgp thanks for the reply. Yes, you are right but i am getting a #error in the textbox and all the textboxes are winking.

i have attached a sample DB can you please check.
 

Attachments

  • Database Sample.accdb
    548 KB · Views: 120

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 13:14
Joined
May 7, 2009
Messages
16,394
see your form.
 

Attachments

  • Database Sample.accdb
    512 KB · Views: 148

jasm1243

New member
Local time
Today, 08:14
Joined
May 21, 2022
Messages
5
Hi, I want to conect two comobox to the wrong serch button. I want to choose two names after that date and then i'll check it out for it




Dim strQuery As String
Dim strWhere As String
Dim lngLen As Long
Const conJetDate = "\#mm\/dd\/yyyy\#"

strQuery = "qry_Inspections"

If Not IsNull(Me.cboWorker) Then
strWhere = strWhere & "([nawjory madaa] = """ & Me.cboWorker & """) AND "
End If

If Not IsNull(Me.txtFrom) Then
strWhere = strWhere & "([rekawtyhatnn] >= " & Format(Me.txtFrom, conJetDate) & ") AND "
End If

lngLen = Len(strWhere) - 5
If lngLen <= 0 Then
MsgBox "No criteria", vbInformation, "Nothing to do."
With Me.qry_Inspections_subform
Filter = ""
FilterOn = False
End With
Else
roi = 8
strWhere = Left$(strWhere, lngLen)
Debug.Print strWhere
With Me.qry_Inspections_subform.Form
.Filter = strWhere
.FilterOn = True
End With
End If
End Sub

Private Sub namecp_AfterUpdate()
Dim strSQL As String
strSQL = "SELECT Table_info.i, tblManager.strManagerName " & _
"FROM tblManager " & _
"WHERE table_info.id__infoo= " & Me.namecp & _
" ORDER BY Table_infoo.nawycompanyy;"
Me.namecp.RowSource = strSQL
Me.namecp.Requery
End Sub
 

Attachments

  • 565.PNG
    565.PNG
    55.6 KB · Views: 59
Last edited:

Gasman

Enthusiastic Amateur
Local time
Today, 06:14
Joined
Sep 21, 2011
Messages
10,544
Hi, I want to conect two comobox to the wrong serch button. I want to choose two names after that date and then i'll check it out for it
Please do NOT crosspost, especially withing the same forum/site.
 

Users who are viewing this thread

Top Bottom