So I have a database of mechanical components. I have a search form in the database that allows the user to apply filters to a query (through the use of 5 text/combo boxes and an "apply filters" button). This query will contain the components that made it past the filter, and some details about those components. Also on the search form, I have a sub-report that is bound to the query.
My plan is to have the user filter though the data using the controls on the form. As the user filters out components, the report should update to display what components pass the new query. They would then select the component they are interested in by clicking on a record in the report, and that component ID would be passed into VBA to do more stuff.
My problem is that the report bound to the query will not update as the query does. I have tried using DoCmd.Requery and Me.Form.Refresh on the button click event, but haven't gotten anywhere. It only works if I close the form, then re-open it.
How do I get my bound report to change dynamically as the user modifies the SQL of its source query?
Here's my click event code:
Private Sub cmdApplyFilters_Click()
Call updateSearchFilters
Me.Requery
Me.Form.Refresh
End Sub
Here's my sub to update the query:
Public Sub updateSearchFilters()
Dim strSQL As String
Dim searchQryDef As DAO.QueryDef
strSQL = searchSQLstrBuilder(Forms("frmSearch").tboCompID, Forms("frmSearch").tboDesc, Forms("frmSearch").cboType, Forms("frmSearch").cboVendor, Forms("frmSearch").tboVendPN)
Set searchQryDef = CurrentDb.QueryDefs("qrySearchRes")
searchQryDef.SQL = strSQL
End Sub
Here's my SQL string builder:
Public Function searchSQLstrBuilder(tboCompID As TextBox, tboDesc As TextBox, cboType As ComboBox, cboVend As ComboBox, tboVPN As TextBox) As String
searchSQLstrBuilder = "SELECT tblDocs.compID, tblComponents.Desc, tblComponents.type, tblComponents.vend, tblComponents.vendorPN "
searchSQLstrBuilder = searchSQLstrBuilder & "FROM tblComponents INNER JOIN tblDocs ON tblComponents.numComp = tblDocs.numComp "
Dim strCompID, strDesc, strType, strVend, strVPN As String
strCompID = tboCompID.Value
strDesc = tboDesc.Value
strType = cboType.Value
strVend = cboVend.Value
If IsNull(tboVPN.Value) Then
strVPN = ""
searchSQLstrBuilder = searchSQLstrBuilder & "WHERE (((tblDocs.compID) Like '*" & strCompID & "*') AND ((tblComponents.Desc) Like '*" & strDesc & "*') AND ((tblComponents.type) Like '*" & strType & "*') AND ((tblComponents.vend) Like '*" & strVend & "*') AND ([vendorPN] Is Null Or (tblComponents.vendorPN) Like '*" & strVPN & "*'));"
Else
strVPN = tboVPN.Value
searchSQLstrBuilder = searchSQLstrBuilder & "WHERE (((tblDocs.compID) Like '*" & strCompID & "*') AND ((tblComponents.Desc) Like '*" & strDesc & "*') AND ((tblComponents.type) Like '*" & strType & "*') AND ((tblComponents.vend) Like '*" & strVend & "*') AND ((tblComponents.vendorPN) Like '*" & strVPN & "*'));"
End If
End Function
Thanks in advance! Let me know if there's more information I can provide.
I don't fully understand this problem, because you can't have a button on a report. They're not interactive. So, I'm assuming you have a button on a form which opens a report.
What you might try is updating the RecordSource of the report. After the updateSearchFilters code runs, at the very end of that function, add:
Reports!rptMyReport.RecordSource = "Select * from qrySearchRes"
Alternatively, you could have a SQL string as a RecordSource and pass variables in using OpenArgs:
Dim strMyValue As String
strMyValue = "This Is A TEST!"
DoCmd.OpenReport "rptMyReport", acViewPreview, , , acWindowNormal, strMyValue
and then in the report you would add this on Form_Load:
Dim strMyValue As String
strMyValue = Me.OpenArgs
Then you can use strMyValue as a parameter in your RecordSource.
It is also possible to pass multiple values via OpenArgs, but it's a little more tricky. You can use a pipe delimiter ("|") to separate your values, but when you open it you'll have to parse out the values on the other side using some VBA.
It's kind of unusual to have a subreport on a form...
After running updateSearchFilters, you need to explicitly Requery the subreport.
Me!subReport.Report.Requery
subReport is the name of the subreport control on the form.
Related
For reasons I cannot see I get the following error message:
Compile error: Method or data member not found
when I use the following:
Private Sub cmd_Add_Click()
Dim strSQL As String
strSQL = " INSERT INTO BERTHAGE " _
& "(BOAT, LOCATION, BERTH_WEEK, BERTH_YEAR, BERTHED) VALUES " _
& Me.Add_Boat & "','" _
& Me.LOCATION & "','" _
& Me.txt_week & "','" _
& Me.txt_year & "','" _
& Me.In_Port & "');"
cmd_Clear_Click
End Sub
Once I click OK and use the refresh button the entry is put into the database, but each time I do an entry I have to go to the same process.
I would like to figure out what method or data is missing?
I should add that there is an outnumber primary key field on this table (Berth_ID), and each time I use the cmd_Add button a new ID number is created for the new record. This includes creating a new ID number for the new record that triggers the error.
Here is all the VBA associated with this form
Private Sub Form_Load()
DoCmd.RunCommand acCmdRecordsGoToLast
End Sub
Private Sub LOCATION_Change()
Me.txt_Cur_Flo = Me.LOCATION.Column(1)
Me.txt_Cur_Doc = Me.LOCATION.Column(2)
Me.txt_Cur_Ori = Me.LOCATION.Column(3)
End Sub
Private Sub cmd_Add_Click()
Dim strSQL As String
strSQL = " INSERT INTO BERTHAGE " _
& "(BOAT, LOCATION, BERTH_WEEK, BERTH_YEAR, BERTHED) VALUES " _
& Me.Add_Boat & "','" _
& Me.LOCATION & "','" _
& Me.txt_week & "','" _
& Me.txt_year & "','" _
& Me.In_Port & "');"
cmd_Clear_Click
End Sub
Private Sub cmd_Clear_Click()
Me.Add_Boat = ""
Me.LOCATION = ""
Me.txt_Cur_Flo = ""
Me.txt_Cur_Doc = ""
Me.txt_Cur_Ori = ""
Me.Add_Boat.SetFocus
End Sub
Private Sub cmd_Close_Click()
DoCmd.Close
End Sub
Consider the best practice of parameterization and not string concatenation of SQL mixed with VBA variables. Due to missing quotes, the compiler attempts to reference a column name and not its literal value. Instead, consider parameterization with defined types which is supported with Access SQL using QueryDefs. Notice below, SQL and VBA are complete separate.
SQL (save as stored query)
PARAMETERS prmBoat TEXT, prmLoc INT, prmBerthed INT;
INSERT INTO BERTHAGE (BOAT, LOCATION, BERTHED)
VALUES(prmBoat, prmLoc, prmBerthed)
VBA
Dim db As Database
Dim qdef As QueryDef
Dim strSQL As String
Set db = CurrentDb
Set qdef = db.QueryDefs("mySavedParamQuery")
' BIND PARAM VALUES
qdef!prmBoat = Me.Add_Boat
qdef!prmLoc = Me.LOCATION
qdef!prmBerthed = Me.In_Port
' EXECUTE ACTION QUERY
qdef.Execute
Set qdef = Nothing
Set db = Nothing
Even better, save your query with form controls intact and simply call OpenQuery:
SQL (save as stored query)
INSERT INTO BERTHAGE(BOAT, LOCATION, BERTHED)
VALUES(Forms!myForm!Add_Boat, Forms!myForm!LOCATION, Forms!myForm!In_Port)
VBA
Private Sub cmd_Add_Click()
Dim strSQL As String
DoCmd.SetWarnings False ' TURN OFF APPEND PROMPTS
DoCmd.OpenQuery "mySavedActionQuery"
DoCmd.SetWarnings True ' RESET WARNINGS
Call cmd_Clear_Click
End Sub
Missing opening parenthesis after VALUES. Also missing apostrophe in front of Me.Add_Boat. These special characters must always be in pairs, an even number by counting.
If Berth_Week and Berth_Year are number fields (and should be), don't use apostrophe delimiters.
If In_Port is a Yes/No field, don't use apostrophe delimiters.
The issue appears to be that I was doubling up the inputs into the 'week' and 'year' field. this was happening (I believe) because those text box fields were already accessing the week and year information directly from the default value on the BERTHAGE table. Essentially I went through each input and would run it individually waiting for the error to occur. Once it occurred I took it out of the INSERT INFO statement. With the removal of week and year, everything is working. That was a painful exercise, and still not complete, but I am back to a function form/DB so I'll take the small victories when they occur.
Private Sub cmd_Add_Click()
Dim strSQL As String
CurrentDb.Execute " INSERT INTO BERTHAGE " & "(BOAT, LOCATION, BERTHED) VALUES ('" & Me.Add_Boat & "'," _
& Me.New_Loc & "," _
& Me.In_Port & ");"
cmd_Clear_Click
DoCmd.Requery
End Sub`
I have a form, below, that allows the user to filter the database multiple ways. When they push the filter button on the form a report populates based on the filter query. The issue is if I filter the database again, even with .requery in the report code, the report doesn't update to the new Query results. I know if I manually close out of the report it works, however when I code it to DoCmd.Close it doesn't actually close the report. If I show it in
acViewPreview it updates each time I use the refilter button on the form but then I cant use buttons on the report. I am trying to make it like a kiosk so I don't want the nav tabs to show.
Filter form
Report
Form Code:
Private Sub btnFilter_Click()
Dim db As DAO.Database
Dim qdf As DAO.QueryDef
Dim SQL2 As String
Dim ToDate As Date
Dim FromDate As Date
SQL2 = ""
Set db = CurrentDb()
Set qdf = db.QueryDefs("Filter")
If cmbFilter.Value = "Vended Date" Then
ToDate = Format(DTPickerTo.Value, "YYYY-MM-DD")
FromDate = Format(DTPickerFrom.Value, "YYYY-MM-DD")
SQL2 = "SELECT CribMaster_Quality.Line,CribMaster_Quality.[Vended Date],CribMaster_Quality.PartNumber,CribMaster_Quality.Group,CribMaster_Quality.ItemNumber,CribMaster_Quality.Amount,CribMaster_Quality.Description,CribMaster_Quality.Cost,CribMaster_Quality.[Extended Cost],CribMaster_Quality.User " & _
" FROM CribMaster_Quality" & _
" WHERE CribMaster_Quality.[Vended Date]" & _
" BETWEEN #" & FromDate & "# AND #" & ToDate & "#" & _
" ORDER BY CribMaster_Quality.[Vended Date] DESC;"
ElseIf ckbDateConst = True Then
ToDate = Format(DTPickerTo.Value, "YYYY-MM-DD")
FromDate = Format(DTPickerFrom.Value, "YYYY-MM-DD")
SQL2 = "SELECT CribMaster_Quality.Line,CribMaster_Quality.[Vended Date],CribMaster_Quality.PartNumber,CribMaster_Quality.Group,CribMaster_Quality.ItemNumber,CribMaster_Quality.Amount,CribMaster_Quality.Description,CribMaster_Quality.Cost,CribMaster_Quality.[Extended Cost],CribMaster_Quality.User " & _
" FROM CribMaster_Quality" & _
" WHERE CribMaster_Quality." & Me!cmbFilter.Value & " = '" & Me!cmbFilterBy.Value & "' And CribMaster_Quality.[Vended Date] " & _
" BETWEEN #" & FromDate & "# AND #" & ToDate & "#" & _
" ORDER BY " & Me.cmbFilter.Value & " DESC;"
Else
SQL2 = "SELECT CribMaster_Quality.Line,CribMaster_Quality.[Vended Date],CribMaster_Quality.PartNumber,CribMaster_Quality.Group,CribMaster_Quality.ItemNumber,CribMaster_Quality.Amount,CribMaster_Quality.Description,CribMaster_Quality.Cost,CribMaster_Quality.[Extended Cost],CribMaster_Quality.User " & _
" FROM CribMaster_Quality" & _
" WHERE CribMaster_Quality." & Me!cmbFilter.Value & " = '" & Me!cmbFilterBy.Value & "'" & _
" ORDER BY " & Me.cmbFilter.Value & " DESC;"
End If
qdf.SQL = SQL2
Set db = Nothing
Set qdf = Nothing
DoCmd.OpenReport "CribMasterReport", acViewReport
End Sub
Report Code:
Private Sub btnReFilter_Click()
DoCmd.Close , acSaveNo
DoCmd.OpenForm "Filter Database Form"
End Sub
Private Sub Report_Load()
Me.Requery
With VendedDatetxt
.Requery
End With
With ItemNumbertxt
.Requery
End With
With Linetxt
.Requery
End With
With PartNumbertxt
.Requery
End With
With Usertxt
.Requery
End With
With Amounttxt
.Requery
End With
With Costtxt
.Requery
End With
With ExtendedCosttxt
.Requery
End With
End Sub
Issue 1: Requerying the Report
When a report is opened using standard techniques, such as clicking on a report in the Navigation pane or when opening a report using DoCmd.OpenReport, Access creates a default instance of the Report that is accessible via the Application.Reports collection. Before the report is first opened or if the default report instance is completely closed (i.e. removed from memory), the Application.Reports collection will not contain an instance of the report. Before accessing the default instance, ensure that the report is already open.
Like other MS Office object-model collections, Application.Reports does not have a "Contains" method or other direct way to test whether a report is already open, only by looping through numeric indexes and testing each report object. Although it seems sloppy to me, the easiest method is to use error handling to try getting the report directly, then catching the error if it's not found:
On Error Resume Next
Set frm = Application.Reports("CribMasterReport")
If err.Number <> 0 Then
'Default instance not open
End If
CAUTION: Do not refer to the report using the class name like an object, as in Report_CribMasterReport.Requery. If you do that, VBA will automatically create a new, hidden instance of the report, but it is NOT the same default instance as described above and this new instance will not be accessible via the Application.Reports collection. Likewise, using the properties and calling methods on such an object will be largely ineffective. (It is possible to create and use such independent instances, but that is an advance technique riddled with its own pitfalls and challenges.)
As the question describes, which is also confirmed by other online sources, the Report.Requery is not effective in refreshing the report after the underlying query or data have changed. However, resetting the Report.RecordSource forces a full refresh of the report when in normal Report View.
Issue 2: Report not closing
The DoCmd.Close command was missing a comma. It should be DoCmd.Close , , acSaveNo. Even better is to always use explicit names for optional parameters. Typing an extra parameter is definitely worth the saved frustration and time with typos in an ambiguous list of commas:
DoCmd.Close Save:=acSaveNo
Issue 3: Unnecessary calls
It is completely unnecessary to call Requery on the report and every single control in the Report_Load event. I get that you were trying to debug the situation, but this behavior should happen automatically. Also, the Form_Load event occurs only once when the form is first loaded, so that code would not be called again unless the report is completely closed and reopened.
Finally some alternative code
Private Sub btnFilter_Click()
'... Include previous code to reset report query
'* Call DoCmd.OpenReport every time to
'* 1) Ensure default report is open
'* 2) Automatically activate the report (even if it was already open)
DoCmd.OpenReport "CribMasterReport", acViewReport
On Error Resume Next
Dim frm As Report_CribMasterReport
Set frm = Application.Reports("CribMasterReport")
If Err.Number = 0 Then
'* Force the Report object to re-run query and recreate report
frm.RecordSource = frm.RecordSource
End If
End Sub
It is no longer be necessary to completely close the report.
Private Sub btnReFilter_Click()
''DoCmd.Close Save:=acSaveNo
DoCmd.OpenForm "Filter Database Form"
End Sub
Private Sub Report_Load()
'* Eliminated unnecessary Requery calls
End Sub
I'm getting error in ms access while trying change subform recordsource based on combo box
The SELECT statement includes a reserved word or an argument name that is misspelled or missing, or the punctuation is incorrect.
here my code
Private Sub Text4_AfterUpdate()
If (Me.Text4.Value = "(ALL)") Then
filterORIGIN_COD = "SELECT SUMMARY.DEST_CITY, SUMMARY.DESTINATION, Count(SUMMARY.CNOTE_NO) AS CountOfCNOTE_NO1" & _
"FROM SUMMARY" & _
"WHERE (((SUMMARY.ORIGIN_CODE) Like " & "'" * "'" & ")))" & _
"GROUP BY SUMMARY.DEST_CITY, SUMMARY.DESTINATION, SUMMARY.TGL_DATA, SUMMARY.ORIGIN_CODE, SUMMARY.ORIGIN, SUMMARY.DEST_CODE;"
Else
filterORIGIN_COD = "SELECT SUMMARY.DEST_CITY, SUMMARY.DESTINATION, Count(SUMMARY.CNOTE_NO) AS CountOfCNOTE_NO1" & _
"FROM SUMMARY" & _
"WHERE (((SUMMARY.ORIGIN_CODE)=" & """Me![Text4]""" & ")))" & _
"GROUP BY SUMMARY.DEST_CITY, SUMMARY.DESTINATION, SUMMARY.TGL_DATA, SUMMARY.ORIGIN_CODE, SUMMARY.ORIGIN, SUMMARY.DEST_CODE;"
End If
Me![OUTBOUND_DETAIL].Form.RecordSource = filterORIGIN_COD
Me![OUTBOUND_DETAIL].Requery
End Sub
ADDITIONAL
actually I'm trying to filter subform (query record source), can someone show me better ways to do that? :)
If trying to filter subform in a trigger event, simply use DoCmd.ApplyFilter or DoCmd.SetFilter (for Access 2010+) methods which are also available in macros:
Private Sub Text4_AfterUpdate()
DoCmd.ApplyFilter , "[SUMMARY.ORIGIN_CODE]='" & Me![Text4] & "'"
End Sub
I have a form whose recordsource is a Query Called qryProdSearch whose SQL is generated using VBA based on search parameters as defined below:
What the code below does is that is splits the text search box into multiple items in an array to allow me to search for all of them simultaneously like Google Search.
iSQL = "SELECT tblProduct.ProductID, tblProduct.ProdDescription, tblProduct.Brand, tblProduct.ShortCode, tblProduct.BarCode, tblProduct.MRP, tblProduct.Discount, tblProduct.TaxRate, tblProduct.LandingCost, tblProduct.MarketPrice From tblProduct WHERE ((([ShortCode] & ' ' & [Brand] & ' ' & [ProdDescription] & ' ' & [BarCode]) Like '*"
If Nz(Me.txtSearch, "") = "" Then
iSQL = "SELECT tblProduct.ProductID, tblProduct.ProdDescription, tblProduct.Brand, tblProduct.ShortCode, tblProduct.BarCode, tblProduct.MRP, tblProduct.Discount, tblProduct.TaxRate, tblProduct.LandingCost, tblProduct.MarketPrice From tblProduct"
Exit Sub
Else
iArray = Split(Me.txtSearch, " ")
End If
If UBound(iArray) = 0 Then
iSQL = iSQL & Me.txtSearch & "*'));"
Else
iSQL = iSQL & iArray(0) & "*'"
For i = LBound(iArray) To UBound(iArray)
iSQL = iSQL & " And ([ShortCode] & ' ' & [Brand] & ' ' & [ProdDescription] & ' ' & [BarCode]) Like '*" & iArray(i) & "*'"
Next i
iSQL = iSQL & "));"
End If
CurrentDb.QueryDefs("qryProdSearch").SQL = iSQL
This is working fine.
However the subform that is using this query is not refreshing no matter what I try till I reopen the form. I have tried the following:
Me.sfrmProdSearch.Requery
Me.sfrmProdSearch.Form.Requery
Me.sfrmProdSearch.Form.Refresh
Me.Form.Requery
Me.Form.Refresh
Any Suggestions would be welcome. Bottomline I do not want to reopen the form but i want it to be refreshed such that the subform shows the filtered content
If I alternatively use the Searchbox directly in the RecordSource of the SubForm and refresh the subform it works fine. example below. But the limitation is that i cannot split the words and make it search using all the words independent of their position.
WHERE ((([ShortCode] & ' ' & [Brand] & ' ' & [ProdDescription] & ' ' & [BarCode]) Like "*" & [Forms]![frmProdSearch]![txtSearch] & "*"));
You may need to refresh the QueryDefs:
CurrentDb.QueryDefs("qryProdSearch").SQL = iSQL
CurrentDb.QueryDefs.Refresh
Then:
Me!sfrmProdSearch.Form.Requery
I tested this on Microsoft Access 2021, it works:
Me.sfrmProdSearch.Form.RecordSource = "qryProdSearch"
By reassigning the subform .RecordSource after modifying the query definition.
I have a Database that we use to create Bills of Materials from Tags in AutoCAD. Because of the nature of this, I need to create 3 separate queries. One for our "Steel", one for our
"Non-Steel", and one for our "Uncut Tubes".
The SQL for the Queries is as follows:
Steel:
SELECT DISTINCTROW Sum([CUT-LENGTH-WEIGHT]) AS [SumOfCUT-LENGTH-WEIGHT], Sum([CUT-SHEET-WEIGHT]) AS [SumOfCUT-SHEET-WEIGHT], Sum([TOTAL-SHEETING-WEIGHT]) AS [SumOfTOTAL-SHEETING-WEIGHT], Sum([TOTAL-ITEM-WEIGHT]) AS [SumOfTOTAL-ITEM-WEIGHT]
FROM [13-1302 Cut-Lengths];
Non-Steel:
SELECT tbl2013BOM.fJobID, Sum(tbl2013BOM.fWeight) AS SumOffWeight
FROM tbl2013BOM
GROUP BY tbl2013BOM.fJobID
HAVING (((tbl2013BOM.fJobID)=23));
Uncut Tubes:
SELECT DISTINCT [13-1302 Cut-Lengths].[TOTAL-LENGTH-WEIGHT], [13-1302 Cut-Lengths].MATERIAL, [13-1302 Cut-Lengths].ORDER
FROM [13-1302 Cut-Lengths]
ORDER BY [13-1302 Cut-Lengths].ORDER;
I have a ComboBox that chooses the Job Number (For Main and Uncut Tubes, e.g. 13-1302) and a Textbox that displays the JobID (For Non-Steel).
Is there a way that I can set up the SQL shown above to look at the ComboBox and TextBox Values, instead of me having to change them by hand?
EDIT
I figured it all out now. (Thank you Elias)
Basically, I cannot use a Field on a table as a RecordSource in SQL, in other words, Combo26 cannot be the Table in an SQL Query. HOWEVER, what CAN be done is to use VBA to inject that value into an SQL Definition, then use that definition as a Recordsource.
I will place the code for my Button below so anyone can use it and reference it:
Private Sub Command27_Click()
Dim dbs As Database
Dim rstSQL As DAO.Recordset
Dim strSQL As String
Dim strSQL2 As String
Dim strSQL3 As String
Dim Field As String
Set dbs = CurrentDb
Field = [Forms]![frmBOM_Combined]![Text26].[Value]
strSQL = "SELECT DISTINCTROW Sum([CUT-LENGTH-WEIGHT]) AS [SumOfCUT-LENGTH-WEIGHT], Sum([TOTAL-SHEETING-WEIGHT]) AS [SumOfTOTAL-SHEETING-WEIGHT], Sum([TOTAL-ITEM-WEIGHT]) AS [SumOfTOTAL-ITEM-WEIGHT] FROM " & "[" & [Forms]![frmBOM_Combined]![Text26].[Value] & "]" & ";"
strSQL2 = "SELECT tbl2013BOM.fJobID, Sum(tbl2013BOM.fWeight) AS SumOffWeight FROM tbl2013BOM GROUP BY tbl2013BOM.fJobID HAVING (((tbl2013BOM.fJobID)= " & [Forms]![frmBOM_Combined]![Combo25].[Value] & "));"
strSQL3 = "SELECT DISTINCT [TOTAL-LENGTH-WEIGHT], [MATERIAL], [ORDER] FROM " & "[" & [Forms]![frmBOM_Combined]![Text26].[Value] & "]" & " ORDER BY [ORDER];"
Debug.Print strSQL
Debug.Print strSQL2
Debug.Print strSQL3
DoCmd.OpenForm ("frmEstWeight")
Forms!frmEstWeight.RecordSource = strSQL
Forms!frmEstWeight.frmTestBomWeight.Form.RecordSource = strSQL2
Forms!frmEstWeight.frmTotalLengthWeight.Form.RecordSource = strSQL3
End Sub
This is working exactly as it should with no errors or anything.
This is within a form correct?
If so, replace the manual values you put in with
REST OF THE QUERY HERE " & Me!Controlname.value & " REST OF THE QUERY HERE
and if you are using something with a control source then just reset the control source value.
me!ControlWithResult.control source = "SELECT tbl2013BOM.fJobID, Sum (tbl2013BOM.fWeight) AS SumOffWeight
FROM tbl2013BOM
GROUP BY tbl2013BOM.fJobID
HAVING (((tbl2013BOM.fJobID)=" & me!controlname.value & "));"
For Non-Steel try:
On the VBA for the popup form
me!Combo25.rowsource = "SELECT tbl2013BOM.fJobID, Sum(tbl2013BOM.fWeight) AS SumOffWeight
FROM tbl2013BOM
GROUP BY tbl2013BOM.fJobID
HAVING (((tbl2013BOM.fJobID)=" & forms!MAINFORMNAME! &"));