access create a report from a form input - vba

I have a need to create a report from a user input on an Unbound form.
I have two tables where the data will come from:
Table Name: RMAMaster
Fields:
RMANbr (5 digit number)
DateIssued (date in MM/DD/YYYY format)
CompanyName (text)
CustNbr (6 digit number)
Table Name: RMAItems
Fields (that are relevant for the search):
RMANbr (relationship established to RMAMaster.RMANbr)
PartNbr (text)
Warranty (Yes/No)
Disposition (lookup from another table)
The form (Name: RMA Report Search) has the following Controls on it, the idea being that the user can fill in any number of fields. Blank fields would mean "Search all for that field" and filled in fields would be "search for the data in those fields".
CustNbr (being in the RMAMaster table)
PartNbr (being in the RMAItems table)
Date Opened <start> to <end> (being in the RMAMaster table)
Disposition (being in the RMAItems table)
Warranty (drop down with choice "Yes", "No" and "Any") (being in the RMAItems table)
(Possibility to add more fields as the user sees fit)
For example, I enter in Part number "G-5645" and leave "Warranty" as "any" and it will search for all the RMA's that have the part number "G-5645" and display them in the report. the report would be paid out sort of like this:
RMAMaster.RMANbr RMAMaster.DateIssued RMAMaster.CustNbr, RMAMaster.CompanyName
|
|-- RMAItems.PartNbr RMAItems.Warranty RMAItems.Disposition
|-- RMAItems.PartNbr RMAItems.Warranty RMAItems.Disposition
|-- (possibly repeated depending on how many items the customer sent back
I can build the report but I'm not wrapping my head around getting the data from the Form RMA Report Search and build a Report off of it. Do I use a Query? VBA Code that calls the report? Not sure how I should go about doing this. Any help would be appreciated.
Thanks!

If I understand you, you want to 'build' a report based on a search form. If that's correct, you don't need to build a report at run-time, but instead build a report based on a query that combines the fields you'd ultimately want to display from RMAItems, RMAMaster tables. The recordsource for this report should be this query.
Next, from the search form a user would select all applicable fields and open the report (maybe a button-click)? This button-click would generate a WHERE statement based on the selected fields. Rpt_Results would be the report you want to generate, stLinkCriteria is the criteria you want to pass. Iteratively build the linking criteria by adding to stLinkCriteria.
Dim stLinkCriteria As String
dim stDocName as String
stDocName = "RPT_Results"
stLinkCriteria = "[" & [PARTNumber] & "]=" & forms!FRM_Search.PartNumber
...
DoCmd.OpenForm stDocName, , , stLinkCriteria

Related

(Access) search text field for strings matching those in another table's field and display these matching records in a subform

Here's my situation,
tbl_products / frm_products
ID__products
products__name (short text)
products__description (short text)
tbl_articles / frm_articles
ID__articles
articles__name (short text)
articles__body (long text)
I have a form bound to tbl_articles containing a subform bound to tbl_products.
What I would like to happen is,
once a user enters text into the articles__body field, (using the After Update module)
it searches this long text field for any words which match a product name
and then (in the subform) displays the matching products.
For example if the articles__body record that the user is currently viewing contains 'product 1', it will display product 1's record in the subform.
Perhaps After Update is not appropriate as it needs to appear to remember these matches. For example, if tbl_articles' record 1 matches/displays product 1 on the subform whereas record 2 matches/displays products 2,3 and 4; I need the user to be able to revisit record 1 and see the product 1 match without having to edit the text (and trigger the After Update).
I have no idea where to start with this. It's not a simple if string contains, Originally I entertained the idea of something like - Like '* [in tbl_products, record 1's products__name] *' repeated for each record (obviously not the correct syntax but simply identifying the process to myself), however this is impractical because the number of strings to match against will grow over time as more products are added.
Any help would be great,
Kind regards
Set Filter and FilterOn properties. Suggest naming subform container control different from the form it holds, like ctrProducts.
Me.ctrProducts.Form.Filter = "InStr('" & Me.articles_body & "', [products_name])>0"
Me.ctrProducts.Form.FilterOn = True

Filter a Report based on user input

I created a report template which I want to open a single page report based on a specific IDENT NO. All of the fields in the report are then generated from the associated IDENT NO.
Currently, when I open the report, it will create a single page report for each ID number in the Report Data table when opened.
Instead, when the user is attempting to open the report, I want to prompt the user to enter the identification number of the specific report they are looking for so that it only opens that single individual 1 page report associated with the entered IDENT NO.
How could I achieve this filtering?
An alternative to using InputBox is to use a "parameter query" (documentation here)
Anywhere in a query criteria or report design view you may enter [IdentNoVariable] and a dialog box will appear (when the report or query is run) asking you to "Enter Parameter Value" for IdentNoVariable.
For example, if you wanted to restrict an ID # during a query (say the query that your report calls):
The dialog box seen appeared upon running the query and has the text of the variable seen in the query criteria. This same thing can be done in a report by entering [IdentNoVariable] into the part of the report where the entered value is desired.
You can display an InputBox for the user to insert the ID and then open and filter the report.
Dim id As String
id = InputBox("Enter the identification number:", "YourInputBoxTitle")
'if a value was entered, open and filter report
If Len(Trim(id)) > 0 Then
DoCmd.OpenReport "ReportName", acViewPreview, , "[IDENT NO] = " & id, acWindowNormal
End If

Generating Report from User Inputs in Access Form

Goal: To create an access form that takes user inputs combines those with a bound value in an access query calculates a final number and then generates a report.
The only issue I am having here in referencing the user inputs on the form to the actual report.
Any suggestions?
In the report it would be:
=Forms!YourUserInputFormName!txtUserInputBox
The form must be left open.
Design your query so that the field to filter by is just a data field, then use the WhereCondition parameter of OpenReport.
DoCmd.OpenReport "YourReportName",acViewNormal,,"My field=" & Me.txtUserInput
Variation for text field and Preview instead of Print:
DoCmd.OpenReport "YourReportName",acViewPreview,,"My field='" & Me.txtUserInput & "'"

DoCmd.OpenReport Asks for values Access07

I have a form that opens a report based on a combo box selection.
Which looks like.
The invoice shipment button opens the report via
DoCmd.OpenReport "ItemList4", acViewReport, , "ShipRef = " & Me.SRCB
SRCB is the combo box next to the shipment label.
When clicking the invoice shipment button I always get asked what the parameter value for S100018 is, so obviously it knows what the value is but isn't applying it to the filter when opening the report like so
How do I prevent this from happening?
I always create a query with a where clause that refers back to the textbox in the form. Then I build the report on the query, which selects 1 record, and I get my report.
I'l show a quick demo, here is a table named Persons:
Then create a form with a textbox, I named the form PersonForm:
Now creat a query that selects everything from the Persons table. In the where clause, open the builder, browse to the created form and select the textbox.
Then we create a very simple report with the report wizard, based on the query.
Now we go back to our created form and add a button. In the button, select for the option to open a report.
Now if you open the form in Form view, enter the name Ivo in my instance. And then click the button.
Of course you have to adjust the example to your context.
Create a query with the data that you need to generate the report. Then add a where clause in the query to the list box where you display your shipment id. Then let the report get the data from the query.
The problem seems to be the report. It looks like it's accesing a variable called S100018. Is this intended behaviour?
The problem was that it was not sending the filter argument as a string
it should be as such
DoCmd.OpenReport "ItemList4", acViewReport, , "ShipRef = '" & Me.SRCB & "'"

VBA for taking information from text boxes and inserting into table

So I have an input form that I want to use to update a table with certain fields of information. I have the ID of the record automatically coming up in a text box. I have three text boxes that I need to add to the table (excluding the ID) on a button click.
Name
Date
Method
are the field names.
As_Name
As_Date
As_Method
are the text box names
The table name is POC, and the ID is POC_ID (its an autonumber).
So I do not want these objects (text boxes) to be bound to the table because this is a little separate "pop-up" form that comes from a form that the table, and I only want the input to be relative to the POC_ID that is already selected via the original form.
So how do I write the vba for this to 1)check to make sure that records do not already exist....2)update the fields (listed above) with data input from the text boxes(listed above). I want to be able to use this with a button click....
EDIT:
actually it is one table not two; i have two forms that I want to be able to send information to the same table (different information though). this db was already built by someone else and know I have been deamed to take it over.
I need to add a second little pop up form for additional information to be added based on new requirements (there is literally no where for me to place this on the other one). I have already done that, and used a suggested object approach to reference the first forms (from which this second "pop-up" form springs from) to add the relative id fields. Now I have this second little pop up form that just asked three values to be inputted (which are the ones listed above).
I just simply do not know how to link the text box, with a field so that once a user enters in the information, clicks "save" it saves the information to the table relative to the TripID that is there (one mentioned above). the only way I know how to get the text boxes to save data to the table is to use the builder/wizard when I create a new one.
I would like to learn how to link an object (text box, cmb, list) etc on a form, to a table with an "On Click" method so that I can use a save button. Basically that is it!
The OpenForm method of DoCmd allows for several arguments, including Where and Openargs. You can take advantage of these.
However, something seems to be quite wrong with your table design in that you appear to be holding the same information in two tables and for no stated reason. Have you read http://www.r937.com/relational.html?
I would suggest that the design you need probably only includes a numeric field POC_ID that is a foreign key to the main table.
Still not sure I understand your situation, but let me offer the outline of an answer. If my outline is not close enough, please explain where I went astray.
Your parent form, frmParent, has a command button (cmdMoreFields) which opens the child form (frmChild) where you will enter values for 3 additional fields in the record currently displayed in frmParent. After the user enters those values in frmChild (in text box controls named As_Name, As_Date, and As_Method), she will click a command button (cmdSave) to store those values to fields (Name, Date, and Method) in table POC, and close frmChild. Also, frmParent includes a text box (txtPk_field) which holds the value for the primary key (field pk_field in table POC) of the current record.
However, I'm not sure which field/control you're using for txtPk_field, and doubt that value is available if the the current record has not yet been saved. So, I'll suggest this code for the cmdMoreFields "on click" event:
If Me.Dirty Then Me.Dirty = False
DoCmd.OpenForm "frmChild"
In the "on click" event of cmdSave (on frmChild), try code similar to:
Dim strSql As String
strSQL = "UPDATE POC SET [Name] = """ & Me.As_Name & """, [Date] =#" _
& Me.As_Date & "#, Method = """ & Me.As_Method & """ WHERE pk_field = " _
& Forms!frmParent.txtPk_field & ";"
Debug.Print strSql
CurrentDb.Execute strSql, dbFailOnError
DoCmd.Close
If that approach works, consider passing the pk_field value to frmChild with Openargs, as Remou suggested.
Note: I assumed the data type for Name is text, Date is date/time, and Method is text. You will have to change the UPDATE statement delimiters for any fields whose data types differ from my guesses.