Toggling the Caption on a continuous Form - ms-access

On a continuous form I am attempting to toggle the caption of a toggle button to match the button’s state. In this case when the record/state is True, I would like the button to read “Current” and if the record is False have the button read “Obsolete”.
The script below works in switching between the two desired values but is switches all of the visible buttons and not for the individual records. I am not sure how to tie the individual records to the individual togglebutton's caption.
Private Sub Toggle5_Click()
If Me.Toggle5.Value = True Then
Me.Toggle5.Caption = "Current"
Else:
Me.Toggle5.Caption = "Obsolete"
End If
End Sub
I am using MS- Access 2013, I expect this question has been answer before, I have not found a working solution.

As Gustav wrote, you cannot do this directly. All static properties of controls in a continuous form always apply to all instances of that control.
Possible workaround:
Use a textbox (disabled & locked, perhaps with special effect = Raised) to show the text, with a control source like this:
= IIf([Status]=True, "Current", "Obsolete")
Put a transparent button on top of it, for easy clickability (it won't show a Click animation though).
Use Conditional formatting to set the background color of the textbox.

You can't.
An unbound control in a continuous form carries the same values and properties on all records.

Related

Paste a value in a textbox on the second tab of a navigation form access vba

I'm quite new to VBA and I've been looking around but cannot seem to find a solution to my problem.
I have made a navigation form (frmNavigation) with 3 buttons, each referring to a different form, let's call them frm1, frm2 and frm3. In the navigationform the control buttons to switch between tabs are all named differently (btn1, btn2, btn3), but the subform that shows either frm1, frm2, or frm3 has the same name: “NavigationSubform” (this shows a different form depending on which tab is clicked on, based on the 'navagation target name' referring to frm1, frm2 and frm3).
When I want to refer to a textbox (txtBox1) on form 1 (first tab) and insert a value i can do this by:
Forms!frmNavigation!NavigationSubform.Form!txtBox1.Value = "insert awesome text"
But how would I refer to txtbox10 on the second tab (frm2)? Just using the following does not work:
Forms!frmNavigation!NavigationSubform.Form!txtBox10.Value
You then get the error 2465 (can't find the field).
I’ve been trying many different things, but can’t seem to get it right. So how do I refer to a textbox on a different tab than the first one?
Help us much appreciated!
Only one subform can be loaded at once. So you've just got to break this process into two steps.
Store the value from txtBox1 somewhere outside of the NavigationSubforms (a textbox on the parent form with visible = no, a global variable or a table works).
In frm2's On Load event, set txtbox10 to be the value you stored.
Just note, that you will need to add conditions in the On Load event if you want to avoid that textbox being set to an empty string or a wrong value if you have a setup where your filter is changing.

MS-Access 2010: setting focus without selecting / highlighting field contents

What I'm looking for is deselecting / dehighlighting a field's contents by using vba, just as if the user would click with the mouse in that field. Maybe the solution is too easy to have found its way to forums ? Simple goal, but it seems difficult to be achieved. SendKeys always got errors. The .OnClick property does not simulate a click, just tells what to do on click.
My form (main- with subform) has many fields between which the focus is moved depending on the fields values. For this I'm using xyz**.SetFocus**
Works fine so far, but in many fields the user should be able to immediately edit the contents by keyboard, without first clicking into that field with the mouse. The keyboard arrows should move the cursor, not highlight the next or previous field. Combobox fields should not be highlighted at all.
There is a database option (File/Options/Client Settings/) which should enable this by selecting "Go to start of field" or "Go to end of field". However, this does not work on combobox fields (optically bad). Moreover, this option should not be set for the whole database but depend on which form has focus, and even better on the field getting focus and its contents.
You can use the .SelStart and .SelLength properties.
With Me.myCombobox
.SetFocus
.SelStart = 0
.SelLength = 0 ' Nothing selected
End With
With Me.myCombobox
.SetFocus
.SelLength = Len(.Text) ' Content selected
End With

if checkbox is marked, then create msgbox with form value in access

So I have an access form based on a table. The form has a list of colors and a yes/no checkbox next to it. If the user marks the checkboxes then clicks a button, i want a msgbox to appear to show all the colors next to the marked checkboxes. Here is the code I currently have, it does not run if I click the button a second time. It also sometimes only shows the first color and is buggy in general.
Form looks like this
Red x
Blue
Green x
Yellow x
Code looks like this
private sub command5_click()
dim rs as dao.recordset
set rs=me.recordsetclone
rs.movefirst
do while not rs.eof
if rs!checkboxes = true then
msgbox rs!color
end if
rs.movenext
loop
set rs=nothing
end sub
You need to add Me.Dirty = False at the top of command5_Click. Requerying the recordset is overkill - you lose your scroll position and your current record.
When you have a continuous form, data is written out to the database when focus is moved from the current record to a different record. This does not happen when you move focus to a control in the header or footer. This is by design, as it is a useful feature. Here's why:
Suppose you had a 3rd field in your database, a text field called "essay" where you could write a 10-line essay all about the color. The field is too big to show on the continuous part of the form, so you add a bound textbox to the form footer. As you move up and down through the color records, the essay for the current color will show at the bottom of the form. And it will be editable. When you click on the Essay textbox, the current record is still being edited. The current record can have bound controls in the header, detail and footer, and edits in any of those places will all be written to the DB simultaneously.
When you move focus to an unbound control (such as command5), it's no different. The current record is still the current record, even though none of its bound controls currently have the focus.
Whenever you want the current record to remain the current record, but to force its edits to be written to the DB, you use Me.Dirty = False.
As to why command5 only works the first time you click it? I have no idea!

How to put a label as link at the end of coloumns in a subform (Datasheet) in Access 2000?

I have a database created in access 2000. A form with a subform (datasheet - defaultview) in it. I have added a label at end of the coloumns in subform and given hyperlink to open the object present in database itself. But when the form open nothing is visible after the coloumn ? I got four coloumns and had hide two columns via onload event of subform. the code is below
Me.SubGroupname.ColumnHidden = True
Me.GroupName.ColumnHidden = True
Me.BNFno.ColumnHidden = False
Me.BNFno.ColumnWidth = -2
Me.SubGroupName1.ColumnWidth = -2
How can I make it visible so that it will appear as a link at each row ?
Please help me.
If I understand you properly, you cannot use Datasheet view to display a control at the end of a row. Switch to Continuous Forms view, it will give you more control, but you will have to work a little harder to get a nice layout.
Alternatively, add a click event to one of the existing columns.

Access: Display Textbox Control In Sub-report when it has No Data

In a subreport I created a sub on detail_format event that will display a text when there is no data returned.
‘Code in sub-report
Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)
If Me.Report.HasData Then
Me.Label43.Visible = True
Me.txtNotEntered.Visible = False
Else
Me.Label43.Visible = True
Me.txtNotEntered.Visible = True
End If
End Sub
It works fine on the subreport when run alone. When I run the main report it doesn’t trigger.
I added the same code in the main report to see if it would work. It runs through the lines of code but still cannot see the txtNotEntered textbox control.
‘Code in main report
Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)
If Me!rptResults_Comments.Report.HasData Then
Me!rptResults_Comments.Report.Label43.Visible = True
Me!rptResults_Comments.Report.txtNotEntered.Visible = False
Else
Me!rptResults_Comments.Visible = True
Me!rptResults_Comments.Report.Label43.Visible = True
Me!rptResults_Comments.Report.txtNotEntered.Visible = True
End If
End sub
I am using MS Access 2003.
Since the subreport is bound to the main report, the subreport itself will not be shown if there is no data to connect it to the main report. You can see this better by setting the background color of the subreport's detail section to red, or any other non-white color.
One workaround is to move your txtNotEntered control to the main report and put it "under" the subreport control (using Send to Back). Then set your subreport control's Can Shrink property to True.
Then, when there is data in the subreport you will see the subreport and it will cover the txtNotEntered control. When there is no data, the subreport will shrink out of the way and you will be able to see the txtNotEntered control.
One advantage to this approach is that it requires no code. Just leave the txtNotEntered Visible property set to True. The shrinking of the subreport will take care of revealing it when appropriate.
In addition to the answer from mwolfe02, I would suggest instead of using a label and VB code use a textbox with the following expression:
=IIf([HasData],"","No data found")
I use this on all my reports. An expression like
=IIf([rptResults_Comments].[Report].[HasData],","No data found")
should work as well. I didn't test the latter expression, so I'm not sure if [Report] is needed or not.
In addition to #rick's problem, how to display "No data" text when a subreport has No Data, it is also common enough to want to handle the case where main report controls reference subreport controls (and the subreport(s) has(have) No Data). This might occur when you are calculating a total that references subtotals from many subreports.
So we can put together #mwolfe02's and #TheOtherTimDuncan solutions (repurposing from #TheOtherTimDuncan his use of the HasData property), with some incidental additions of my own, as a checklist.
We have a main report rptMain and a subreport srpSub. In rptMain, detail section, we have a subcontrol sbctSub which references srpSub.
On rptMain create a label (there's no general need for it to be a textbox) lblNoData with whatever text you like (e.g. "No Data Returned"). Place lblNoData under sbctSub (using Send to Back). Use the same Top value. This ensures these don't overlap vertically so problems don't occur when Shrinking/Growing occurs.
Add an "annotating" label that is always viewable by a developer in design view but is permanently set to Visible = No (which makes it invisible in non-design views) with text like "Hidden lblNoData under subcontrol". If this needs to shrink (Can Shrink = Yes) then make it an unbound textbox. Colour such an annotating label (or textbox) to stand out in design view (e.g. I generally use a blue). Otherwise, down the track, there's a danger of losing sight, as a developer, of what's going on (worse still if another developer has to analyze your work).
Ensure the following are set to Can Shrink = Yes:
rptMain, Detail.
sbctSub.
When srpSub has no data then lblNoData will be revealed to the user as sbctSub will have shrunk to zero.
In production there might be issues with the No Data label showing through (white backgrounds seem to act transparently in some circumstances). If so, in rptMain:
Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)
Me.lblNoData.Visible = (Not Me.sbctSub.Report.HasData)
End Sub
(My "design spike" testing worked as #mwolfe02 mentioned. That is, no additional code was necessary and I could rely on the subcontrol to hide and reveal the No Data label as needed. However my production report had these weird transparency issues.)
If you have any control on rptMain (e.g. txtGrandTotal) that references a control on srpSub, then set the control source as follows
=IIf([sbctTemp].[Report].[HasData],[sbctTemp].[Report]![txtSubTotal],0)
Null to zero Nz() won't work where the referenced control doesn't even exist, due to the subreport returning no data.
Edit 01: Added additional code to hide and show the No Data label in case of transparency issues. Rearranged this from being listed the last step, to being listed more sensibly in the order.
Edit 02: Made mention that the annotating label should be a textbox if it needs to shrink.