Author Archives: Robert

MySQL ALTER TABLE ADD COLUMN IF NOT EXISTS

I had been looking for a one-line solution for adding columns to tables when they do not already exist. For the longest time I settled on using a temporary stored procedure, but this still required at least four lines to execute using the 3rd party system I am sometimes constrained within…

DROP PROCEDURE IF EXISTS `AddColumnIfNotExists`;
DELIMITER $$ CREATE PROCEDURE `AddColumnIfNotExists`() BEGIN DECLARE CONTINUE HANDLER FOR SQLEXCEPTION BEGIN END; ALTER TABLE `t1` ADD `c1` TEXT; END $$ DELIMITER ;
CALL `AddColumnIfNotExists`();
DROP PROCEDURE `AddColumnIfNotExists`;

While that works fine, I was still displeased with having to use a stored procedure to achieve the desirable result. So, I eventually came up with this beautiful one-liner…

Continue reading

C# Ignore DropDownButtonPressed for ToolStripButton Converted to ToolStripSplitButton

When you convert a ToolStripButton to a ToolStripSplitButton, the underlying event code is not automatically converted. So you may notice clicking the split button’s down-down arrow also triggers the button’s Click event.

You can either move the Click event code to the new ButtonClick event (preferred), or adjust the Click event to ignore the drop-down arrow.

Continue reading

C# Pass Click Event to MenuStrip or ToolStrip Control Without Form Focus

More often than not, I want the click event for menus (MenuStrip) and toolbars (ToolStrip) to trigger on the first click, even when the firm does not have focus. I figure if Windows is going to show the hover effects, the user expects the click to trigger without having to first focus focus on the form.

A work around is to use your own ToolStrip and let the mouse activation give the control the focus, which in turn will then let the button fire it’s click event:

LarsTechStackOverflow Answer
Continue reading

Two ways to have your C# application run during Windows start-up

The simplest method, in my opinion, relies on the Windows registry.

using Microsoft.Win32;

namespace WindowsStartupTest
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();

            checkBoxRegistry.Checked = (registryKey().GetValue(Application.ProductName) != null);

        }
        private RegistryKey registryKey()
        {
            return Registry.CurrentUser.OpenSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\Run")!;
        }
        private void checkBoxRegistry_Click(object sender, EventArgs e)
        {
            if (checkBoxRegistry.Checked)
            {
                registryKey().SetValue(Application.ProductName, Application.ExecutablePath);
            }
            else
            {
                registryKey().DeleteValue(Application.ProductName, false);
            }
        }
    }
}

Another method is to add an application shortcut to the Windows Startup folder.

Continue reading

Convert Your Mac QuickBooks Company to a QuickBooks for Windows Backup (QBB) and Vice Versa

  1. Open your QuickBooks company as the admin on the Mac.
  2. Open the File menu, select Export, then To QuickBooks for Windows.
    • If prompted to Verify before backing up, do it.
  3. Choose a location for the new QBB file, then click Save.
  4. Confirm all remaining prompts.
  5. Copy the QBB file to a Windows PC.

How to Restore a QuickBooks Backup File (QBB) on Windows

Continue reading

Caps Lock Alert for Password Input Fields

<input type="password" id="password">
<span id="warning" style="display:none;color:#c00">[Caps Lock]</span>
<script>
document.getElementById("password").addEventListener("keyup", function(event) {
  document.getElementById("warning").style.display = (event.getModifierState("CapsLock")) ? "inline" : "none";
});
</script>
Excel VBA

VBA EXCEL: Mirror Comments to Matching Cells of Another Spreadsheet in the Same Workbook

I have an Excel workbook with 13 protected sheets, January through December plus a Summary that needed the same cell comments for each month.

There were 2 options…

  • Type comments into each sheet manually; then update 11 sheets (Feb-Dec) by hand whenever comments need changing 😬
  • Add VBA code to the workbook that automatically duplicates cell comments from January (unprotected) to February through December (protected) when those sheets are activated 😎
Continue reading