_Click on TabHost view is not working - basic4android

On a TabHost view I found there are 3 events. Click, LongClick and TabChanged. I found that only TabChanged works and I would like to use Click since the user may tap a tab and go back to the home screen and may want to tap the same tab again.
Here is the Sub Routine I used with TabChanged, but I would like to use Click instead. Maybe I need to change something in my code other than just changing the _TabChanged to _Click. If so, could you let me know what to change?
Sub tbhPagesEventHandler_TabChanged
ToastMessageShow(tbhPages.CurrentTab,False)
' These will make the code easier to read.
'-----------------------------------------
Dim intVisitsTab As Int : intVisitsTab = 0
Dim intMaintenanceTab As Int : intMaintenanceTab = 1
' Start the activity the user wants.
'-----------------------------------
Select tbhPages.CurrentTab
Case intVisitsTab
StartActivity("Visits")
Case intMaintenanceTab
StartActivity("Maintenance")
End Select
End Sub

I see you found a solution, based on your comment, but thought I'd post this for future readers in case it was useful.
The 'TabHost.Click' event fires when the content of the TabHost tab is clicked, not the tab itself.
If you use the following for your code, you can see the difference (this uses tbPages as the TabHost variable):
' Displays the 0-based index of the tab being activated
Sub tbPages_TabChanged
Msgbox("Current tab is " & tbPages.CurrentTab, "")
End Sub
' Fires when you click inside the content of the tab page,
' not on the tab itself.
Sub tbPages_Click
Msgbox("Current tab is " & tbPages.CurrentTab, "")
End Sub
This means you can use the CurrentTab property to determine which page the user has selected, and react accordingly:
Sub tbPages_TabChanged
Dim TabIdx as Int
TabIdx = tbPages.CurrentTab ' Get the tab just activated
Select TabIdx
Case 0
' First tab is now active
Case 1
' Second tab active
Case 2
' Third tab active
Case Else
MsgBox("Something is badly wrong! We have only three tabs", "HEY")
End Select
End Sub

Related

Select Slides based on keywords in Powerpoint

I'm trying to create a macro that will select any slide that contains a keyword in the title, but not getting anywhere. The ppt includes different frontpages, disclaimers and content slides and the idea is to add keywords to the titles of each slide and get the macro to select and export the selected slides to PDF.
I've got the export part working, but have the enter the slide numbers manually.
I got the code below from a similar question, but can't rewrite it to select the slides instead of presenting the answers as a MsgBox. Can somebody help, please?
Sub FindText()
Dim sld As Slide, shp As Shape, list As String, myPhrase As String
myPhrase = InputBox("enter a phrase", "Search for what?")
For Each sld In Application.ActivePresentation.Slides
For Each shp In sld.Shapes
If shp.HasTextFrame Then
If Left(shp.Name, 5) = "Title" Then
If Not shp.TextFrame.TextRange.Find(FindWhat:=myPhrase) Is Nothing Then
If list = "" Then list = sld.Name Else list = list & ", " & sld.Name
End If
End If
End If
Next shp
Next sld
MsgBox list
End Sub
My full code, using Steve's solution, if anyone is trying to solve the same problem:
Sub SelectedSlidesToPDF()
Dim sld As Slide, shp As Shape, list As String, myPhrase As String
myPhrase = "WhatYouLookFor"
For Each sld In Application.ActivePresentation.Slides
' FIRST, hide the slide:
sld.SlideShowTransition.Hidden = True
For Each shp In sld.Shapes
If shp.HasTextFrame Then
If Left(shp.Name, 5) = "Title" Then
If Not shp.TextFrame.TextRange.Find(FindWhat:=myPhrase) Is Nothing Then
' UNHIDE the slides that contain your keywords
sld.SlideShowTransition.Hidden = False
End If
End If
End If
Next shp
Next sld
'EXPORT slides
ActivePresentation.ExportAsFixedFormat ActivePresentation.Path & "\" & "MySelectedSlides " & Format(DateSerial(Year(Date), Month(Date) - 1, 1), "yyyy-mm") & ".pdf", ppFixedFormatTypePDF, ppFixedFormatIntentPrint, RangeType:=ppShowAll
' UNIHDE all slides in presentation
For Each sld In ActivePresentation.Slides
sld.SlideShowTransition.Hidden = msoFalse
Next sld
End Sub
By default, when you save as PDF, the PDF won't include any slides that are hidden, so you can simply hide all the slides first, then UNHIDE any that you want to include in the PDF. While I haven't done this here, you'll want to UNHIDE all the slides again after saving to PDF.
For Each sld In Application.ActivePresentation.Slides
' FIRST, hide the slide:
sld.SlideShowTransition.Hidden = True
For Each shp In sld.Shapes
If shp.HasTextFrame Then
If Left(shp.Name, 5) = "Title" Then
If Not shp.TextFrame.TextRange.Find(FindWhat:=myPhrase) Is Nothing Then
' UNHIDE the slides that contain your keywords
sld.SlideShowTransition.Hidden = False
End If
End If
End If
Next shp
Next sld

Navigate programmatically through the records of a continuous form

I would like to navigate through the records of a continuous form in Access 97. I don't find how to do it. This is what I tried:
Me.RecordSetClone.MoveFirst moves to the first record logically, but not in the UI. Also the CurrentRecord property does not change.
I cannot set the CurrentRecord property, it is readonly. Me.CurrentRecord = 1 gives an error.
DoCmd.GoToRecord Record:=acFirst seems to have no effect.
What is the correct way to move to the first record in a continuous form (and to the next/previous)?
Use the Bookmark property of RecordsetClone and Form.
Caveat: I'm pretty sure all this worked in Access 97, but that was a really long time ago.
Sub DemoNavigate()
Dim RS As DAO.Recordset
Set RS = Me.RecordsetClone
RS.MoveFirst
' or
RS.AbsolutePosition = 0
' Navigate in form
Me.Bookmark = RS.Bookmark
' next record
RS.MoveNext
' or
RS.AbsolutePosition = 1
Me.Bookmark = RS.Bookmark
' Move to searched record
RS.FindFirst "someField = 42"
Me.Bookmark = RS.Bookmark
End Sub

MS Access: Link listbox to textbox

I have a textbox and listbox, one is for entering a new topic in a help form while the other looks up those new topics. I would like to be able to present the finished topics in both the textbox and listbox simultaneously to edit or lookup as well write new records in the help form. The listbox provides functionality to view which records there are now.
I find if I put nothing in and I go to a new record the prev/next buttons will stop working, maybe there is a control I need to add to keep it from freezing or to refresh? Normally I press esc to get out of a new record edit and return to others but that does not work as usual.
Or how else may I point to the listbox's current record source?
I currently have this code:
Private Sub List35_AfterUpdate()
DoCmd.GoToRecord acDataForm, "Help Form_Editor2", acGoTo, Me.List35.ListIndex + 1
Me.List35 = Me.List35.Column(0, Form.CurrentRecord - 1)
Dim index As Integer
index = Form.CurrentRecord - 1
Me.Text53 = Me.List35.Column(Me.List35.ListIndex + 1, index)
End Sub
I keep getting some of the items to read but others are null. I have about 8 items in the source table... what is going wrong? Why would there be nulls?
Another issue after getting this updated. When the code is setup the recordset starts at new when I allow additions and edits on the form. The code displays the list item as it should but the other items will not activate from the requeried listbox item. What might correct this issue?
Private Sub List35_AfterUpdate()
Dim myTitle As String
With Me.List35
If .ListIndex > -1 Then
'Use this one if you are using bound column
myTitle = .Column(1, Form.CurrentRecord)
'use this if you want something other than the bound column
'and you have more than one column in the list (hidden or not)
'nId = .Column(1, .ListIndex)
Me.RecordSource = "SELECT * FROM FormsHelpTable WHERE HelpTitle = '" & myTitle & "'"
Me.Text53.Value = myTitle
Else
Me.RecordSource = "SELECT * FROM FormsHelpTable WHERE HelpTitle IS NULL"
'Me.Text53.Value = "(New)"
End If
End With
Me.Requery
End Sub
This checks for ListIndex. It will be -1 if you don't have anything selected.
Private Sub List35_AfterUpdate()
Dim index As Integer
With Me.List35
If .ListIndex > -1 Then
DoCmd.GoToRecord acDataForm, "Help Form_Editor2", acGoTo, .ListIndex + 1
.Value = .Column(0, Form.CurrentRecord - 1)
index = Form.CurrentRecord - 1
Me.Text53 = .Column(.ListIndex + 1, index)
End If
End With
End Sub
I'm not sure what all your code is trying to do, so I didn't make any other adjustments other than to reduce all references to List35 to a single With statement.
I normally do something like this:
Private Sub List35_AfterUpdate()
Dim nId As Long
With Me.List35
If .ListIndex > -1 Then
'Use this one if you are using bound column
nId = .Value
'use this if you want something other than the bound column
'and you have more than one column in the list (hidden or not)
'nId = .Column(1, .ListIndex)
Me.RecordSource = "SELECT * FROM TableName WHERE Id = " & nId
Else
Me.RecordSource = "SELECT * FROM TableName WHERE Id IS NULL"
End If
End With
Me.Requery
End Sub

link Open/Libre Office button to cell and reference cell in macro

I would like to add a [set of] standardized macro[s] to some of the cells of a custom spredsheet (Open/Libre/Star Office).
Said macro should be activated using a Form PushButton dropped into the relevant cell[s].
I experience several problems all relative to the access of the "relevant cell":
If I try to Anchor to Cell a PushButton it goes to A1 and not to currently selected cell.
I can connect a Basic fragment to the button, but I found no way to retrieve the "relevent cell" (i.e.: the cell containing the button).
What I am trying to do (as a first working example) is to add a button to increment the numeric value of the cell (possibly disabling direct editing; I want that value to go up by one at each button press and no way to otherwise change cell).
Is such a thing possible at all?
Any example (or pointer to docs) very welcome.
NOTE: This question gives some hints on how to solve problem in VBA (Excel), but I found nothing for [L|O|S]Office
You can find the cell containing the button from a handler as follows:
Sub ButtonHandler(oEvent)
Dim sControlName$
Dim oSheet
Dim nCount As Long
Dim i As Long
Dim oPage
Dim oShape
Dim oAnchor
sControlName = oEvent.source.model.Name
oSheet = thiscomponent.currentcontroller.activesheet
nCount = oSheet.drawpage.count
oPage = oSheet.drawpage
For i = 0 To nCount - 1
oShape = oPage.getbyindex(i)
'oControlShape = oPage.getbyindex(i).control
If (oShape.supportsService("com.sun.star.drawing.ControlShape")) Then
If oShape.control.Name = sControlName Then
oAnchor = oShape.anchor
If (oAnchor.supportsService("com.sun.star.sheet.SheetCell")) Then
Print "Button is anchored in cell: " + oAnchor.AbsoluteName
Exit For
End If
End If
End If
Next i
End Sub
I know, it is not pretty is it? I added significant error checking.If you then want to know what cell was active when you clicked the button, you can call this routine
Sub RetrieveTheActiveCell()
Dim oOldSelection 'The original selection of cell ranges
Dim oRanges 'A blank range created by the document
Dim oActiveCell 'The current active cell
Dim oConv 'The cell address conversion service
Dim oDoc
oDoc = ThisComponent
REM store the current selection
oOldSelection = oDoc.CurrentSelection
REM Create an empty SheetCellRanges service and then select it.
REM This leaves ONLY the active cell selected.
oRanges = oDoc.createInstance("com.sun.star.sheet.SheetCellRanges")
oDoc.CurrentController.Select(oRanges)
REM Get the active cell!
oActiveCell = oDoc.CurrentSelection
oConv = oDoc.createInstance("com.sun.star.table.CellAddressConversion")
oConv.Address = oActiveCell.getCellAddress
Print oConv.UserInterfaceRepresentation
print oConv.PersistentRepresentation
REM Restore the old selection, but lose the previously active cell
oDoc.CurrentController.Select(oOldSelection)
End Sub

initialize ms access form fields

Is there a generic VBA code for initializing all fields on an MS Access form? I am very weak in the VBA coding department but i would like to have the form initialized in the following 2 conditions:
1) When someone double clicks the form to open it.
2) After someone clicks the "save" button to save the newly created record.
Any help would be greatly appreciated.
edit
i have tried using the me.refresh code in the "on click" event and it does not seem to initialize all fields. The only code in the form is the following:
Private Sub Form_BeforeUpdate(Cancel As Integer)
Dim ctl As Control
On Error GoTo Err_BeforeUpdate
If Me.Dirty Then
If MsgBox("Do you want to save?", vbYesNo + vbQuestion, _
"Save Record") = vbNo Then
Me.Undo
End If
End If
Exit_BeforeUpdate:
Exit Sub
Err_BeforeUpdate:
MsgBox Err.Number & " " & Err.Description
Resume Exit_BeforeUpdate
End Sub
The only differences between #'s 1 and 2 are the event handlers.
1
Private Sub Form_Load()
DoCmd.GoToRecord , , acNewRec
End Sub
2
Private Sub SomeButton_Click()
'Your code to save the record the user entered
DoCmd.GoToRecord , , acNewRec
End Sub
Both of these Subs should go to the next (new) record.
On Me.Refresh :
Me.Refresh only updates the records in the current form, but will not show new or deleted records.