Libre Office Calc Data Range Source empty - mysql

I have a table in MySQL (really is a "View") that I changed the Name. It was used in a Calc spreadsheet Control (Text box and clicked on it) to update some cell contents. After the Name change Calc control does not work. I searched Internet, played with Calc all day and could not a fix so far. Basically, in "Define Database Range" window the "Source" section on the bottom is empty, and it is not editable. The macro runs without error but produces nothing. Why is the "Source" empty, and how to set it up to the proper source?

Finally figured out - maybe not the best solution.
Data>Define range>Select the range with problem (source missing for some reason)
Data>Define range: recreate the same range with desired name
Ctrl+Shift+F4 will open up Mysql data source; select the desired table or query; content will appear in the top right window
Click on the top left corner of the output table; Data-to-text icon will appear in row above
Click on Data-to-text icon and the table will be inserted into the active range in the spreadsheet
Now the Data>Define range selected range will have the proper SOURCE filled in as the data source of the range
Last, I had to recreate the macro that is assigned to the Text box Control. The macro is Data>Select Range + Data>Refresh Range + whatever else...
Now my original method of clicking on the text box to refresh data in the spreadsheet from MySQL works again!

Related

Google Sheets. Run a script to set existing dropdowns by Index number

I have a sheet with about 60 dropdown data validation controls. I would like to set groups of them to a value, based on an index number of the values in the drop down e.g.
dropdown contains values "cat", "dog, "bug", "ant", and I would like to set the value to "dog" by setting the dropdown value to index 2.
I can't find the syntax for the index, so I have used setVaue(), which works, but is not the desired method:
var dropdownRanges = ["dd_w", "dd_y","dd_y", "dd_z"];
for (var i=0;i<dropdownRanges.length;i++){
sheet.getRange(dropdownRanges[i]).setValue("Dog");
}
An example dropdown is shown below. I'd like to programatically set the dropdown to display the first item (Index 1) in the list, using google script. this is to "reset" the dropdowns to a default value.
The items differ in all the dropdowns, so I must use the index, and cannot the text value.
example dropdown in google sheets
I feel a bit embarrassed that I can't find an equivalent to "setIndex", but then I am migrating from Excel to Google Sheets, and still haven't grasped the new ecosystem.
The way I did this is, I got the data validation options from the cell (A5 in this case), get the top option (the 0th option), and then i set the cell equal to it. this resets the cell to the top option
let option_0 = sheet1.getRange('A5').getDataValidation().getCriteriaValues()[0].getValue()
sheet1.getRange('A5').setValue(option_0);

Automatic Replace "0" with blank cell

I have a sheet called "Test". Column B shows dynamic API calls, then I use a macro to copy all cells from Column B to Column C every 1 hour in order to store those prices, however sometimes API call fails, so it shows 0. I want to mass replace all cells containing "0" (match exact case) from all columns of sheet "Test" without changing Column B (which is the column for the API calls so we don't want to change its formula).
How can I do that?
Thank you!
Google sheets doesn't have this function yet but this could do the trick:
Select all cells (Ctrl + A) click Format > Conditional Formatting
Use the dropdown to select Equal To and type 0
Tick the text tickbox and change the text color to white, this will
effectively hide all your zero values.
You can define a format as
0;-0;

Google Apps Script - Going up from bottom of sheet to an available value

I'm trying to do a macro in google sheets where I select a point in column N (in this case N100) and then simulate control up button to move up to the next available value in column N. But when I do this, I see the cell that's activated is the top of the column (looks like control up is pressed twice).
The code I have is below, any ideas on why this seems to be the case?
function ClearFormq() {
var sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Team1");
sheet.getRange("N100").activate()
sheet.getCurrentCell().getNextDataCell(SpreadsheetApp.Direction.UP).activate();
}
Thanks!

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.

Prompt box, ask value, store in cell. Add button for adapt

I'm new to the world of google sheets. I was able to program very simple routines in Excel. Sorry if I couldn't find the answer anywhere on this site.
My question is simple, has 2 parts:
I would like to prompt a question box on opening the google sheet, asking a numeric value, after answering this, storing the numeric value to a specific cell, e.g. B3.
I would like to have a button on multiple pages of the sheet, prompting the same question box to edit the value.
Background:
I'm a medical doctor, I've created a sheet with many medications for small children in emergency situations. I would like a ask the user the age (and maybe later the weight, it's now calculated) of the child, so the age and weight are correct on all pages and the user is not in a hurry to find the right cell. If the user would like to edit the age, he uses the button, available on all sheets.
First, with the following function you can ask the user for the age and set it to a specific cell in a specific sheet:
function promptUserAge()
{
// Prompt for the value
var age = SpreadsheetApp.getUi().prompt("Please enter the age.").getResponseText();
// Get the sheet that you want store the value in and set the value in the cell B3
SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Patient Information").getRange("B3").setValue( age );
}
Now, since you used the phrase
so the age and weight are correct on all pages
I am not sure if you are going to set the value in multiple sheets, and are you going to do that with Sheets functions or app script. That is why I am going to include the method to set the value in all sheets, in specific cell:
function promptUserAge()
{
// Prompt for the value
var age = SpreadsheetApp.getUi().prompt("Please enter the age.").getResponseText();
//Get all pages in spreadsheet and iterate through
var sheets = SpreadsheetApp.getActiveSpreadsheet().getSheets();
for(var i = 0; i < sheets.length; i++ )
{
//Set the value in the cell B3 of the page
sheets[i].getRange("B3").setValue( age );
}
}
To get the prompt to pop-up when user opens the Spreadsheet you use call it in the onOpen function:
function onOpen(e)
{
promptUserAge();
}
And now, the part where you add the button to edit the value.
You could add a custom menu that would appear in the Spreadsheet's toolbar with a custom menu like this :
function createMenu()
{
SpreadsheetApp.getUi().createMenu("Fill information")
.addItem("Age", "promptUserAge")
.addToUi();
}
This is a good way if your users know what to look for, meaning that you have told them the custom menu exists. From my experience, some people have trouble finding the menu even if you tell them it is there, so since your background suggests you want to create an easy and fast way I would use the second method:
You could insert an image to the Spreadsheet by navigating from it's toolbar: Insert -> Image. Insert an Image that says 'Push here to edit information' in a very clear way and right click the image. You get the borders to edit the image size and in it's upper-right corner appears three dots. You click the dots and then "Assign script...". To the prompt, insert the function name without the parenthesis. In this example you would insert:
promptUserAge
Now the image works as a button to call the function.
I hope this helped.