Modules & VBA :: Creating Recordset - Using Array As Report Data Source
Apr 17, 2015
I've done some basic work with arrays.. writing array data to form list objects.. How to use an array as a data source for a report?
Would i need to create a recordset and populate it with the array, then bind the report to it ?
The reason I am asking is the previous developer here built every app using arrays and UDT's... the apps are completely disconnected from the data. Everything is loaded in to arrays..
I have the following script which I use to modify all report settings, with an array so that I can easily list reports that I want to change the settings for, there could be 50+ reports.
I can use a string but I have to put str1 as string, str2 as string etc... whereas an array would be easier (if I knew how to do it).
Code: Public Sub ModifyAllReportsProperties() Dim obj As AccessObject, dbs As Object Set dbs = Application.CurrentProject Dim ReportName As String
I have a table with multiple records per individual.. I need to search through all of their results to flag up those in a query that do not match the approved list..
what is the best way to do this? I am trying a recordset loop but am struggling a bit...
here is my code so far
Private Sub Command0_Click() Dim rst As DAO.Recordset Dim dbs As DAO.Database Dim strSQL As String Dim strPscale As String
strSQL = "SELECT Eng_Speaking, Eng_speaking from qry_Sub1_crosstab_Crosstab;" Set dbs = CurrentDb Set rst = dbs.OpenRecordset(strSQL) Me.Text1 = ""
Do While Not rst.EOF strPscale = rst.Fields("Eng_Speaking") & ";"
rst.MoveNext
Loop Me.Text1 = strPscale Set rst = Nothing End Sub
but I need to somehow incorporate an array into this to check the score...
I have a table with application records. One of the fields captures schools the applicant will work at. This field stores data in comma delimited format. There could be 1 school name; there could be 5 school names.
My ultimate goal is to build a report which shows me records of all applications, grouped by school choice. I want to see: School A was selected by 5 people, School B was selected by 7, etc.
Is it possible to write a query from this table that will enable this?
Here's my goal: 1) to set up a 7 column table containing a list of 147 numbers from a recordset (StNumberRS) and 2) to compare those numbers to a separate recordset containing a partial list of those numbers (completedStores). If one of the numbers in the completedStores list matches a number on the StNumberRS list show the 'icon_yes.gif' image, otherwise show the 'icon_no.gif'.
I can loop through the StNumberRS and set up the 7 column table, but I'm stuck trying to loop through the completedStores list while inside the StNumberRS loop.
Could someone look through my code and see where I've gone wrong?
Thank you! Code:<% Dim StoreRS, Query, AltRow, ProjectQuery, ProjectRS, CompletedStores_variable, strValue, CompletedStores_ArrayProjectQuery = "SELECT * FROM Projects WHERE Id =" & Request("Id")Set ProjectRS = Connect.Execute(ProjectQuery)CompletedStores_variable = ProjectRS("CompletedStores") CompletedStores_Array = Split(CompletedStores_variable,",")Dim StNumber_variable, StoreList_ArrayQuery = "SELECT StNumber FROM Stores ORDER BY StNumber"Set StoreRS = Connect.Execute(Query)StNumber_variable = StoreRS("StNumber") StoreList_Array = Split(StNumber_variable,",")%><table width="100%" border="0" cellspacing="0" cellpadding="10"> <tr> <td> <%If Not StoreRS.EOF Then%><!-- Display store list in a table, showing 7 stores in each row: --> <TABLE width="800" cellspacing="0" cellpadding="2"><tr><td colspan="14" align="center" bgcolor="#FFFF00" class="subtitle">PROJECT STATUS</td></tr><tr class="required"> <td>STORE #</td><td>DONE</td><td>STORE #</td><td>DONE</td><td>STORE #</td><td>DONE</td><td>STORE #</td><td>DONE</td><td>STORE #</td><td>DONE</td><td>STORE #</td><td>DONE</td><td>STORE #</td><td>DONE</td></tr><tr bgcolor="#CCCCCC"><td colspan="14"><img src="../images/spacer.gif" width="1" height="1"></td></tr> <% Dim i, theCount, remainder theCount = 0i = 0Do While Not StoreRS.EOF' The StoreList_Array contains 147 numbersFor i = LBound(StoreList_Array) TO UBound(StoreList_Array)' The CompletedStores_Array can vary from zero to 147 elements. Each strValue is one element of the array.'For Each strValue In CompletedStores_Array' As long as theCount equals 7, create an empty row separaating the table rows...remainder = theCount Mod 7If remainder = 0 thenIf theCount <> 0 thenResponse.Write "<tr><td colspan='14'><img src='../images/spacer.gif' width='1' height='1'></td></tr>"Response.Write "<TR>"End IfEnd If'... and create a table row populated with 7 elements from the StoreRS("StNumber"). If StoreRS("StNumber") = CompletedStores_Array(i) Then Response.Write "<TD align='right' valign=top>" & StoreRS("StNumber") & "</td><TD align='center' valign=top><img src='../images/icon_yes.gif' width='13' height='13'></TD>"Else' Output value of current CompletedStores_Array element for debuggingResponse.Write "<TD align='right' valign=top>" & StoreRS("StNumber") & "</td><TD align='center' valign=top><img src='../images/icon_no.gif' width='13' height='13'>" & CompletedStores_Array(i) & "</TD>"End If If remainder = 6 thenResponse.Write "</TR>" & VbCrLfEnd If theCount = theCount + 1i = i + 1StoreRS.MoveNext'next next Loop ' close out the last table row if its not alreadyIf remainder = 0 thenResponse.Write "<TD colspan='12'> </TD></TR>" & VbCrLfEnd If If remainder = 1 thenResponse.Write "<TD> </TD></TR>" & VbCrLfEnd If%> </TABLE> <%Else Response.Write "<p>There currently is no data for this project.</p>"End If%> </td> </tr></table>
I'm trying to parse the following into an Array by splitting the csv file using a "," comma separator. There should be 63 different data pieces in this File. When I do a count of them from the (ubound array) i only get 54. The last data piece on each row gets concatenated to the first data piece of the next line. Is there a way to stop this from happening? This is causing problems with working with the data.
I've been working on a procedure to step through the recordset and add the data one record at a time so I can get rid of the duplicates.
I've tried a few approaches, but this is where I'm at now.
Code:
Dim rs As DAO.Recordset Dim rsHH As DAO.Recordset Dim rsPhone As DAO.Recordset Dim rsEmail As DAO.Recordset Dim rsAddress As DAO.Recordset Dim rsPerson As DAO.Recordset Dim db As DAO.Database Set db = CurrentDb
I have looked through the threads and have not found an answer to my question, so I post it hoping there is an answer as well as documenting useful information for other individuals.
The following code is what I am using to 'pull' data in order to print a certificate. It functions the way I designed it (verified by debug.prints and msgboxes). My question is how do I pass data to a defined report (certificate) based upon the results of a built recordset. When the report opens, the values come up as "#Name?". I'm guessing that the issue is syntax, but I just don't know. Here is the code I have so far (I've even commented it for y'all)...
Looking forward to your comments...
-BT.
Dim RSAgg As Recordset Dim RSsrc As Recordset Dim DB As Database Dim strAgg As String Dim strSQL As String Dim strCert As String
'If there is no week number set, drop out If Not IsNumeric(txtWeekNum) Then MsgBox "You Must Specify a Week Number.", vbInformation + vbOKOnly, "Required Input" Exit Sub End If
' tblAggDesc contains the field names ' that have scores I want to evaluate. ' If someone makes a perfect score, ' then they get a certificate. Fields are ' a1, a2, a3, b1, b2, b3, c1, c2, c3. strAgg = "SELECT tblAggDesc.AggCourse, tblAggDesc.AggDesc FROM tblAggDesc;"
Set DB = CurrentDb() Set RSAgg = DB.OpenRecordset(strAgg)
RSAgg.MoveFirst Do While Not RSAgg.EOF If (Right(RSAgg!AggCourse, 1) > 1) Then 'rounds 2 & 3 contain additional information that is printed on certificate strSQL = "SELECT tblScores.HEDR, tblRoster.Fname, tblRoster.Lname, tblScores.WeekNo, tblScores." & RSAgg!AggCourse & ", tblScores." & RSAgg!AggCourse & "X AS AggCourseX " & _ "FROM tblRoster LEFT JOIN tblScores ON tblRoster.HEDR = tblScores.HEDR " & _ "WHERE (((tblScores.WeekNo)=" & [txtWeekNum] & ") AND ((tblScores." & RSAgg!AggCourse & ")=100));" Else strSQL = "SELECT tblScores.HEDR, tblRoster.Fname, tblRoster.Lname, tblScores.WeekNo, tblScores." & RSAgg!AggCourse & " " & _ "FROM tblRoster LEFT JOIN tblScores ON tblRoster.HEDR = tblScores.HEDR " & _ "WHERE (((tblScores.WeekNo)=" & [txtWeekNum] & ") AND ((tblScores." & RSAgg!AggCourse & ")=100));" End If
Set RSsrc = DB.OpenRecordset(strSQL, dbOpenDynaset) If Not (RSsrc.BOF And RSsrc.EOF) Then RSsrc.MoveFirst Do While Not RSsrc.EOF If (Right(RSAgg!AggCourse, 1) > 1) Then strScore = RSsrc!AggCourseX & "X" Else strScore = "" End If 'MsgBox RSsrc!Fname & " " & RSsrc!Lname & " " & RSsrc!WeekNo & " " & RSAgg!AggCourse & " " & strScore & " " & RSAgg!AggDesc strCert = "Fname='" & RSsrc!Fname & "' AND Lname='" & RSsrc!Lname & "'" & " AND WeekNo='" & RSsrc!WeekNo & "' AND XCount='" & strScore & "' AND AggDesc='" & RSAgg!AggDesc & "'" 'Debug.Print strCert
' this is the point that I have problems. ' I want to pass RSsrc!Fname, ' RSsrc!Lname, RSsrc!WeekNo, ' RSsrc!AggCourseX, RSAgg!AggDesc to ' the report. DoCmd.OpenReport "rptCleanTarget", acViewPreview, , strCert
I want a Text Box Query on my form to display the Status, Workshop, Time, Enrolled and Limit. The problem is these values come from two different tables and the Enrolled value comes from a single field that contains the different workshops.
What I mean is: In Table[Attendees] a row contains a customer's Number, First Name, Last Name, Workshop and Phone Number. The workshops vary for each customer so one row on the table could have John Doe attending Cover Letter Writing and the next row could have John Smith attending Resume Writing. What I want is to be able to count the different workshops within the Field[Workshop] and total them and then display the total in a Text Box Query. I have a Text Box Query set up displaying Status, Workshop, Time and Limit as these values all come from Table[Workshops].
So basically I need to Query to also display a result that is the Total for each workshop from Table[Attendees] and display the total for each workshop in a Query with data from Table[Workshops].
Here is a link to an Example Database [URL] ....
I'm trying to avoid putting things on different reports and the like because the people using this are basically computer illiterate and if they have to click a button (no matter how well labeled) they won't do it and the information might as well not exist.
And if there's a better way to do it, I'm all ears. The only thing is, I have to update these workshops month by month. Since they are dynamic, I want to avoid creating separate tables for each workshop.
I have a form with a record source already defined (used so the user can browse through records and edit them) I have the form store requirement ids and not the name however I would like to present the requirement name rather then the id to the user So it tried with a sql query and a recordset but I keep getting the error data type mismatch in criteria expression on this line Set rsm = dbm.OpenRecordset(sRequirementName1)
I think the problem is having the record source already defined and then having a new Recordset not sure how to work around it
here is the code ---------------------------------------------------------------------------------------------------------------------------------------------------------- Private Sub Next_Click()
Dim sRequirementName1 As String Dim queryResult As String Dim wsm As workspace Dim dbm As Database Dim rsm As Recordset
I have also attached the DB if anyone thinks they can help, if you are confused about what i am trying to do with the modify form i made one with students that works it is the modify hours1 form and the code above is the on click event for the next button
I have 2 forms. On form1, the record source is a query. From form2, I need to iterate through the recordset from form1 and perform some action. How do I access the recordset from form1?
I`m currently having the problem to export data from an SQL server into a table. I managed to open a recordset but I`m incapable of adding the recordset to an existing table. I found similar threads but I am still not able to generate functioning code.
Code: Function fDAOServerRecordset() Dim db As DAO.Database Dim dblcl As DAO.Database Dim rssql As DAO.Recordset
I have a form that allows users to input data into a field called "Checked out". I was wondering how I can create a report that shows the forms (I have about a couple thousand) only with the "checked out" field filled in.
In my database (db) I have first create simple report which can print label for certain article in number of times user wants to. That part of db is marked as OldLabels in db that I have attached bellow.
Now, I plan to update this code via form NewLabels so user could choose more than one article and for each article he can define 'TimesToRepeatRecord' number. Unfortunately, I am little confused how to achieve this.. This is the old code (from Report) which have done most of the work
Code: Option Explicit Dim intPrintCounter As Integer Dim intNumberRepeats As Integer Private Sub Report_Open(Cancel As Integer) intPrintCounter = 1 intNumberRepeats = Forms!VPDEKLARACIJE!TimesToRepeatRecord
[Code] .....
I have also attached db named "Demo" so you could see the issue. [URL] .....
I am trying to filter a recordset with a variable q. The field in the table associated with the record set is of data type Date/time. I assigned data types String and Date to q but both cases generates the error message " Data type mismatched in expression".
I'm trying to populate a listbox from a recordset. I will explain what I'm trying to achieve.
I have a (continuous) form with some data from a table. On the form header I have a listbox, showing all (distinct) customers from that form.
The user is able to do some filtering. That all works great. But I want to populate the listbox with ONLY the customers on the form AFTER filtering.
One way I thought might me the solution was using RecordClone. But I'm stuck there. It must be something simple for an expert. I'm not entirely a newbie, at least not to VBA. Is there an easy way to refer the listbox' recordset to the actual recordset on the form?
I am posting a report to the web, in a pdf format. the issue is I have data that is hidden under conditional formating in which if it meet the criteria the font is white and background white. This is great since it shows up blank on pdf. However if a slick person takes the pdf highlights the page and transfers it to a word document, he can highlight that area change the font to black and see the data. Is there a way to hide the data prior to creating a pdf.
Special situation: The SQL Server Linked Server across the country is linked to a Read Only Oracle DB. This data pull works perfectly and populates the Subform.
The problem is that Oracle can take 3 to 6 seconds to retrieve the single record depending on the network traffic through a small pipe.
The code below shows the RecordSource for the SubForm. clicking on a list box supplies the value. Then 3 to 6 seconds later, the subform populates.
The actual Recordset for this Recordsource is needed to conduct Validation on each field. Normally this would be on SQL Server, I might just create a Recordset Oject and run this SQL statement again in 1 milisecond. In this case, it will probably take an additional 3 to 6 seconds. Avoiding another lengthy round-trip to Oracle would be prefered.
Goal: How does one grab, clone, or other wise reference the existing recordset for the SubForm?
Note: Immediate Window - One single field can be returned quickly
There are 48 fields that need validation - is there a way to reference the entire recordset?
Immediate Window during Break Mode: ? me.fsubsrNavSHLBHL("NavSH_QQ") NESE ' this is the correct value for the current recordsource
Set a breakpoint right after the line: fsubsrNavSHLBHL.Form.RecordSource = "Select * from vsrNavigatorSHLBHL where Well_ID =" & txtNavWellID.Value
Immediate Window: ? me.fsubsrNavSHLBHL.Form.RecordSource Select * from vsrNavigatorSHLBHL where Well_ID =91229
I'm working on creating an events log. In my table I've got a field that pulls the individual's username (that they use to log into the computer) and logs it against their log entry.
As part of my query (for my daily events log report) I'm pulling up said username.
I'd like to give access to the specific user to edit his (and only his) entries from the report, but I'm getting a type mismatch with the below code:
Code: If me.UsernameID = "KraussLJ" Or Environ$("Username") Then DoCmd.OpenForm "frmShiftLog" DoCmd.FindRecord Me.ID, acStart, , acSearchAll, , acAll Else MsgBox ("You are not authorized to edit this entry") End If
(before you ask, "KraussLJ" is our ops manager who insists on having final editorial control over the shift log before sending it higher up the chain)
I can get the msgbox to run if I block out the
Code : Environ$("Username")
, but beyond that I'm a little stuck. Should this be a dlookup function or am I overanalyzing this way too much?
I have access table that stores details as attached. Just to give an example how data is stored , I copied data from Access table to excelsheet. Now I would like to create a report that will run when a button is clicked on the form and the vba code should display the last 7 dates from todays dates in the report along with all the data and colour the record Green,Amber and Red depending upon the Update Date and Target Date. If the Target date exceeds then that records should be coloured "Red" and if todays date equals to Date then the record should be amber and if greater than Date but less than Target Date then it should be Green.
So the report should display the last 7 dates records from todays date and the appropriate color of each record to let everyone know if its under target, meets target etc.
With below codes I am able to export recordset data to specified excel range if recordset count is 25. But I am unable to export the data greater than 25 to 2 specified range.
I have a need to convert the export of an Access report to an ASCII file.
The export needs to have a specific format - described below:
Field Position | Field Length | Field Name | Field format
1-6 | 6 | Member # | text - right justified 7-12 | 6 | Trans Date | YYMMDD 13-15 | 3 | Pay code | Alpha/ NUM - Left 16-26 | 11 | Amount | -9999999.99 (*) 64-71 | 8 | Check # | Right
general comments and questions:
This report needs to interface with some sort of transaction accounting system - No Idea what it is, but this format of the report will interface.
The field positions go from 1 to 73. I need only supply the data above, so the check # is way out of sequence. Do I need to have the space inbetween "Amount" and Check Number in the report? Will a simple text file work with all the fieds together? or will I need the space in there? Is there a way to design a report in an ASCII format in access?
Specific Questions
I think I need to change the format of the amount and date fields. I am currently using the short date format 8/30/04, but need to return the date as YYMMDD - 040830. How can I change this format to reflect the ASCII format. The form is also set with the default "=Date()" so the user doesn't have to enter the date everytime - it can also be edited for older data. I would like the date to appear the way it is on the form 08/30/04 but get entered to the table as 040830. Is there a way to do that?
The amount field is odd - I'll include the exact criteria that is desired:
"All Amount Fields must be right justified and space filled. If the amount is a credit, show the "-" sign at the beginning of the number. Payment should be entered as positive amounts. If zero, assign the fied as 0.00 (space filled)"
Is this just a mask that needs to be added? Currently, The field shows $7.00 when 7 is entered to add cent, you must type in 7.50, tab will put in the "$". I need to get rid of the $ and space fill the field?
how to use the Like statement when creating a record-set of data through VBA. Before I was always able to find work-arounds but now is the time to slay this issue once-and-for-all.A person can build several sales quotes for a specific company and I am trying to find the last sales quote that was built. The function is passed a variable length string and I am trying to build a recordset of all quotes based on the variable. Here is the offending line of code:
strSQL = "SELECT * FROM Quotes WHERE Quotes.ProposalNo Like " & "*" & strProposalBase & "*" & " ORDER By Quotes.QuoteID DESC" (This yields an empty recordset)
strSQL = "SELECT * FROM Quotes WHERE Quotes.ProposalNo Like ""*" & strProposalBase & "*"" ORDER By Quotes.QuoteID DESC" (This yields an Error message stating there is an invalid column name)
strSQL = "SELECT * FROM Quotes WHERE Quotes.ProposalNo Like " & strProposalBase & "*" & " ORDER By Quotes.QuoteID DESC" (This yields an Error message stating there is incorrect syntax near the word ORDER)
I have tried different variations above and beyond these strings and get one of the three listed errors.
i am trying to write a query to produce a descending recordset of photo_id but only one from each user e.g
if these are the top records
photo_id 150 m_name dave photo_id 149 m_name dave photo_id 148 m_name dave photo_id 147 m_name john photo_id 146 m_name john photo_id 145 m_name fred
i want the query to produce this
photo_id 150 m_name dave photo_id 147 m_name john photo_id 145 m_name fred
and so on, there are other fields also but that gives you the idea i hope. what i have come up with is this
SELECT MAX(FORUM_ALBUM.Photo_id) AS ID, FORUM_ALBUM.Photo_Name,FORUM_ALBUM_USERS.M_Name,FO RUM_ALBUM.Member_id FROM FORUM_ALBUM, FORUM_ALBUM_USERS WHERE FORUM_ALBUM.Member_id=FORUM_ALBUM_USERS.MEMBER_ID AND FORUM_ALBUM.Photo_Status=1 GROUP BY FORUM_ALBUM.Photo_id,FORUM_ALBUM.Photo_Name, FORUM_ALBUM_USERS.M_Name, FORUM_ALBUM.Member_id ORDER BY FORUM_ALBUM.Photo_id DESC;
this gives me the records i want in the correct order but it gives multiple instances of each M_Name instead of just one record for each M_Name