Record count in report per page in access - ms-access

***
I have a report that has detail ,I want to display count of the
records per page in the report footer

Steps as outlined in https://www.tek-tips.com/faqs.cfm?fid=3069
1) Place a textbox in the {page} footer, and call it txtPageCount. Be sure to set the Format property to standard, or some other numeric type. Modify the label, e.g., "Page Counts: ".
2) Click on the Report Properties button (which is located to the left of the horizontal ruler, and just below the toolbars). Click on the Event tab, then click on "On Open". Click the 3 dots at the end of the line, then select Code Builder.
3) Go up to the listbox that contains the word "Report", and click on the arrow. Select "(General)". The right listbox should now show "Declarations". Enter this code:
Public intPageCount As Integer
'"Public" variables stay alive until the report finishes
4) Scroll back down to "Private Sub Report_Open..." and paste this code into the procedure:
' the following code initializes the variable
intPageCount = 0
5) Go back to listbox that contains the word "Report", and select "Detail", then select "Print" in the righthand listbox. Enter the following code:
' increment intPageCount for each record printed
intPageCount = intPageCount + 1
6) Go back to the listbox and select "PageFooterSection", and select "Format" in the righthand listbox. Insert this code:
'set the textbox in the footer to intPageCount
txtPageCount = intPageCount
'reset our counter (intPageCount)
intPageCount = 0

Related

Can I store the same option value for more than one toggle button in a control box?

I have a list of questions each with 4 possible answers that are displayed as toggle buttons on my form. What I want to do is if the user chooses either of the first two buttons, the Option Value stored is "1", if they choose either of the last two buttons, the Option Value stored should be "0". The option values must be different for each toggle button in a control group. Is there a way to recode the toggle buttons to store the desired response? (I work in psychology, thus the bait and switch of offering 4 choices to the user when really only two responses are recorded).
Here is what I have tried:
I tried thinking about a recode as jcarroll suggested, but this is a circular reference:
Private Sub Q1_Click()
If Me.Q1 = 1 Or 2 Then
Me.Q1 = 1
Else:
Me.Q1 = 0
End If
End Sub
I could recode into another variable but that is just as clunky as using a SQL statement on the data post-hoc, for instance:
NewVariable=Iif([Q1]=1,1,iif([Q1]=2,1,0)
Finally, I tried to code have both toggle buttons have the same Option Value (which causes both to look pressed if either is pressed) and recode the unpressed toggle button's back color. But while my code looks correct to me, this did not change the pressed color of the toggle button (which I think has to do with over riding toggle button design settings):
Private Sub Frame5_Click()
If Toggle8.Value = True Then
Toggle9.BackColor = &HFF00&
Else
Toggle9.BackColor = &H8000000F
End If
End Sub
I could not come up with any programming solutions on the form itself to solve this. The alternative is that I wrote a procedure to apply to the data after it is collected which will be stored as 1,2,3,4 to convert it to 0 or 1. This procedure also sums up the 1's. I have 50 variables/questions that will be passed through this procedure (as well as another like it that converts 3&4 to 1).
Public Function Recode1(ParamArray arg()) As Variant
Dim Size As Integer, skips As Integer, i As Integer, result As Variant
'Recodes first two toggle buttons as "1" for AQ assessment
Size = UBound(arg) + 1
For i = 0 To Size - 1
If IsNull(arg(i)) Or Not (IsNumeric(arg(i))) Or arg(i) = -99 Then
skips = skips + 1
Else
If arg(i) = 1 Or arg(i) = 2 Then
result = result + 1
Else:
result = result + 0
End If
End If
End sub

Button click unclick ms-access

In access form, I'm hoping to click on a button and add information to an existing record using an update query. Ideally, when this happens, the button will change colors and appear 'activated'.
Then, if the user decides that the information that has been added needs to be removed, they can click the same button again. This removes the previously added information from the table and changes the button appearance to 'inactive'
You can't change the colour of a command button if you are using Accesss 2003 or earlier, but you can simulate a button using a label, and obviously you can change a labels caption and colours.
If you are using 2007 on-wards then substitute the Label name to your Command button name.
Using the On_current property of your form use something like
If Me.AddData = 1 Then
Me.YourLabel.Caption = "Remove Data"
Me.YourLabel.BackColor = VbRed
Else
Me.YourLabel.Caption = "Add Data"
Me.YourLabel.BackColor = VbGreen
End If
Then use a similar logic to run your update code from the On_click property of the label, based on the value of AddData.
If you're willing to have -1 and 0 in AddDate these can be easily converted to TRUE/FALSE.
This is taking a few liberties with the info you've given, but it's getting late in the day.
Your form has a command button (Command7) and a textbox (Text8).
Text8 has a control source linked to AddData (so it shows -1 or 0).
This code executes whenever you move to a different record. It checks the value in Text8 and changes the colour of the command button accordingly:
Private Sub Form_Current()
With Me
Select Case .Text8
Case -1
.Command7.BackColor = RGB(0, 255, 0)
Case Else
.Command7.BackColor = RGB(0, 0, 255)
End Select
End With
End Sub
This code on the click event of the command button will change the value in Text8 from True to False and vice versa.
It will then requery the form, forcing the Form_Current event to fire.
A requery moves the recordset back to the first record, so the bookmark moves it back to the record you were looking at.
Private Sub Command7_Click()
Dim bkmrk As String
bkmrk = Me.Bookmark
With Me
.Text8 = Not CBool(.Text8)
.Requery
Me.Bookmark = bkmrk
End With
End Sub
Edit:
Scrap that -1 and 0 malarkey....
Change the Select Case to Case 1 in the Form_Current event.
Change the .Text8 = Not CBool(.Text8) in the Command7_Click event to
.Text8 = Abs(Not CBool(.Text8 * (-1)))

How to display correct page number in body of ssrs(In every page of the output)

i Placed this code in my report property code
Public Function PageNumber() as String
Dim str as String
str = Me.Report.Globals!PageNumber.ToString()
Return str
End Function
and called in my text box in body of report Like this
=Code.PageNumber()
It was not able to repeat textbox on each page.
It is showing the page number as 1 only on first page.
need to show pagenumber in each page of the output in body of the report
Kindly help me on this if u have any solution.
First Follow the steps 1 below to do pagination:
1)
1.1. Click the Details group in the Row Groups pane.
1.2. From the Tablix member Properties pane, expand “Group”-> “PageBreak”.
1.3. Set the “BreakLocation” to “End” and set the “Disable” property to the expression like below:
=IIF(rownumber(nothing) mod 40=0,false,true)
The above point 1 is use to do pagination in Report output(Display only 40 records per page in output)
2) use custom code:
Public Function PageNumberno(val as integer) as String
Dim str as String
str =(val/40)
Return str
End Function
3) Create Calculated column in Dataset and enter =0 in expression
4) In 2 Calculated Column
1)Pageno
2)No in Dataset
In Report Body use Expression for PageNo :
=code.PageNumberno(Rownumber("DataSet1"))
use Expression for No :
=IIF(Instr(code.PageNumberno(Rownumber("DataSet1"))
,".")<>0,
(Left(code.PageNumberno(Rownumber("DataSet1")),
(Instr(code.PageNumberno(Rownumber("DataSet1")),".")-1))+1)
,code.PageNumberno(Rownumber("DataSet1"))
)
5)Right click and insert column on Right Side and in Column name add code in Text box
=ReportItems!No.Value
Note: No is calculated Field column name.
6)Under AdvancedMode
IN Row Group select Static and Set RepeatOnNewPage Properties to True
In the Above Column created under point 5 will display correct page no in every page in body of the report
I have Tried and its working Fine..Try it.
I usually put a text box in the footer of the report (which will automatically display on every page) with the following line of code in it (no report property code needed):
="Page " & CStr(Globals!PageNumber) & " of " & CStr(Globals!TotalPages)

Send message to user if they leave all fields blank when adding data to table; and don't add the data

So, I have a table, 2 forms, a sub form, 2 buttons, and a bunch of text boxes. With these I made a button that pops up an "add field" where you type information into text boxes then click add, and it adds it to the table which back on the other subform shows that data; I have that working. I am not sure how to make it not add the data if you leave ALL fields blank though (note; I only want it to be ALL fields, it's okay if they fill out one field and the rest are null). If all fields are null, it sends out a msgbox to the user saying please fill in data into the text boxes.
Another thing I am looking for for a future part of this database is required fields. Where lets say there are 10 text boxes, and before you can add the data into the table through the form you MUST fill out 6 out of 10 of the text boxes (marked with a * which ones are needed) and if you don't, give them an error saying please fill out [text boxes that weren't filled out] and try again. If all of the 6 required fields were filled out, then it can save it to the table even if the other 4 are null or not.
This is the code I have inside of the add button:
Private Sub CustomerAddBtn_Click()
Dim db As Database
Dim rec As Recordset
Set db = CurrentDb
Set rec = db.OpenRecordset("Select * from CustomersT")
rec.AddNew
rec("CustomerName") = Me.CustomerAddSupplierNameTxt
rec("Address") = Me.CustomerAddAddressTxt
rec("City") = Me.CustomerAddCityTxt
rec("ProvinceState") = Me.CustomerAddProvinceStateTxt
rec("PostalZip") = Me.CustomerAddPostalZipTxt
rec("Phone") = Me.CustomerAddPhoneTxt
rec("Fax") = Me.CustomerAddFaxTxt
rec("CustomerSince") = Me.CustomerAddCustomerSinceTxt
rec("Email") = Me.CustomerAddEmailTxt
rec("Notes") = Me.CustomerAddNotesTxT
rec.Update
Set rec = Nothing
Set db = Nothing
'Send message to user saying it was saved, so they know
Dim intReply As Integer
intReply = MsgBox("Customer has been successfully saved to the database!", vbOKOnly, "Success!")
End Sub
Thanks in advance.
You can check if a Text Box has a value in it by using IsNull(Me.TextBoxName). So, if you want to test if all of the text boxes are empty then you can do something like this
If IsNull(Me.CustomerAddSupplierNameTxt) _
And IsNull(Me.CustomerAddAddressTxt) Then
MsgBox "Please don't try to enter an empty record."
Else
MsgBox "(user filled in at least one field)", vbInformation, "Debug Message"
' your existing database code here
End If
...and just expand the initial If statement to include all of the controls you want to check.
Similarly, for required fields, you can check the value of the controls corresponding to those required fields and display a similar message if any of them IsNull().

Multiple address rows with state list based on country

I have multiple address rows with a state and country combo box. I limit the state list based on the country. It looks like
However, when I change the value of the state and this detail row loses focus, it saves and clears the value of the other state like
I have an event on the state field to set the list when it gets focus.
Private Sub cboState_GotFocus()
MsgBox ("Country: " & Me.cboCountry.value)
If Nz(Me.cboCountry, 0) = 0 Then
MsgBox "Please select a country first"
Me.cboCountry.SetFocus
Else
If Nz(Me.cboCountry.value, 0) = 0 Then
Me.cboState.RowSource = ""
Else
Me.cboState.RowSource = "SELECT id, stateCode, stateName FROM state where country_id = " & Me.cboCountry.value
End If
End If
End Sub
I tried setting 'Limit to List' to No, but it gave an error
I tried setting Column Widths to 0.001";0.3938";1.1806", but then it displayed the id field instead of the state code. Here are the current values
Column Count 3
Column Widths 0";0.3938";1.1806"
Row Source SELECT id, stateCode, stateName FROM state where country_id = [country_id]
Bound Column 1
Limit to List Yes
How can I have multiple state combo boxes, each with a different restricted list based on the country?
An Access combobox whose LimitToList property is set to Yes can only show values returned by the RowSource property, even if the ControlSource is set to another value.
The workaround is to put a textbox on top of the combobox (but not covering the arrow) and show the text value in the textbox, using =Dlookup("textvalue","tbl","Id = " & numericvalue) in the ControlSource property. That way you can show a value that is not in the list.