Thursday, 22 June 2017

Converting lists for use in a SQL 'IN' statement

This website is a massive time saver http://delim.co/ 

Simply paste your list into the textbox, then select you delimiter (comma) then under converter options enter a single quote into open tag and close tag.

This will then produce a list of single quote enclosed comma separated values that you can drop straight into your SQL IN statement

Step 1
A1
B1
A2
B2
A3

B3

Step 2
'A1','B1','A2','B2','A3','B3'

Step 3
Select * from Product where ProductCode IN ('A1','B1','A2','B2','A3','B3')

Wednesday, 30 November 2016

Selecting only visible cells in Excel

I found a neat solution to a problem I have manually been working around for quite sometime.

If you have hidden any rows or columns in Excel and want to copy the remaining data only, or if you have made use of the outlining tool and have created subtotals in your document and you only want to copy those subtotals then you can do so by following these steps;-

  1. Select the data you want to copy
  2. Press Ctrl+G to bring up the "Go To" window
  3. In the bottom left corner click the Special button which will bring up the "Go To Special" window
  4. From this window select "Visible cells only" 
  5. Click OK

Now copy and paste the selection as you normally would.

Tuesday, 1 March 2016

Unable to create offline files in Windows 7

After clicking "Available offline" several times and enabling and disabling offline files I finally stumbled across a solution to make this work.

1. Disable offline files and reboot
2. Navigate to C:\Windows\ 
3. Take ownership of the CSC folder (you may need to also do this to any sub folders)
4. Delete the CSC folder
5. Enable offline files and reboot

Wednesday, 28 October 2015

Creating a sent item in Outlook without sending it

I was asked if it was possible to create an email within Outlook and make it look like it had been sent, without actually ever sending it. This question is very much in the grey area of "Don't ask why?"

After rummaging around on the Internet I couldn't actually find a reliable answer, but I remembered doing something similar with the nickname (.nk2 file) 

1. Open Outlook
2. Click File - Manage Rules & Alters
3. Click Next
4. At the bottom of the window under Start from a blank rule, select 'Apply rule on messages I send'
5. Click Next
6. Tick the box that says 'sent to people or public group' then in the bottom window click on the underlined text 'people or public group'
7. In the To box enter the email address you are sending to then click OK
8. Click Next
9. Tick the box that says 'move a copy to the specified folder' then in the bottom window click on the underlined text 'specified'
10. Select Sent Items and click OK
11. Click Next (twice)
12. Click Finish
13. You will be warned that this rule will only run when Outlook is running, click OK (twice)
14. Either Disable your wireless / Internet connection OR put make Outlook Work Offline.
15. Create a new email and send it.
16. As Outlook is offline the message should stay in your Outbox. Scroll through your folders until you find the Outbox, it should show that 1 message is unread. Click into the Outbox and then delete the email contained within.
17. Navigate to your Sent Items, this should also show 1 unread item which is the email you have just 'sent'
18. If you want to modify the date on a sent item then you can do so by modifying the date / time on your computer. 


I am currently still searching for a simpler solution, and am also looking out for some sort of add-in that may just create the sent object automatically without having to go thorough the steps outlined above

Friday, 24 July 2015

Connect Excel to Microsoft SQL Server and query Database

Open Microsoft Visual Basic for Applications (Alt+F11)

Click Tools – References

Add “Microsoft ActiveX Data Objects 2.7 Library”

Create a new module (I tend to keep all my SQL code in a module of its own e.g. mod_SQL)

Then create a new function or sub routine




Function myFunctionName(ByVal s_myString As String) As Integer

Dim conn As ADODB.Connection
Dim rs As ADODB.Recordset
Dim sConnString As String

'Create the connection string.
sConnString = "Provider=SQLOLEDB;Data Source=Address;" & _ 
"Initial Catalog=DBName;" & _
"User Id=Username; Password=Password"

'Create the Connection and Recordset objects.
Set conn = New ADODB.Connection
Set rs = New ADODB.Recordset

'Open the connection and execute. 
conn.Open sConnString
Set rs = conn.Execute("SQL Statement")

'Check we have data.
If Not rs.EOF Then
myFunctionName = rs("Return Value")
' Close the recordset
rs.Close
Else
myFunctionName= -1
End If

'Clean up
If CBool(conn.State And adStateOpen) Then conn.Close
Set conn = Nothing
Set rs = Nothing

End Function

Wednesday, 27 May 2015

Word / Office 2013 has stopped working

Annoyingly if you look around the web for Word / Office crashing on start up or "has stopped working" you will find thousands of posts all recommending the same thing; start word in safe mode and then disable COM Addins. 

After trouble shooting the issue for 3 hours and trying a variety of things I finally managed to resolve my problem. It seems my users issue was to do with their USB docking station (and the version of the Display link Adapter software they had installed)

I guess I could try upgrading the version of the software, but the user works in a different country so I don't want start uninstalling anything that may cause me to be disconnected. To get them up and running I was able to disable hardware acceleration for office, to do this

Run Regedit
Go to HKEY_CURRENT_USER\Software\Microsoft\Office\15.0\Common
Create a new Key called Graphics
Under the new key create a new DWORD called DisableHardwareAcceleration
Set the DWORD value to 1

Tuesday, 17 February 2015

Excel VBA adding a comment to a cell

Code below can be used to add comments to a cell. I find this useful for providing errors and feedback to the end user.


Dim o_Range As Range

Set o_Range = Sheet1.Range("A1)

o_Range.ClearComments
   
o_Range.AddComment "Test Comment"

Tuesday, 18 November 2014

How to set start value of auto increment in MySQL?

The auto_increment is known as the seed value in MSSQL, if you need to change the sequence of your numbers then you can do so by running the following SQL command

ALTER TABLE tablename AUTO_INCREMENT=9999;

Change the table name to your actual table name and the 9999 to be your actual start value.

Alternatively if you are using phpMyAdmin then select your table and from the top menu select operations, under table options edit the AUTO_INCREMENT field.

This worked in phpMyAdmin version 4.2.7.1

Monday, 20 October 2014

Office 2010 Activation error 0x80070190

An unspecified error has occurred. Your request cannot be processed at this time. Please try again later. (0x80070190)

I’ve had the above error message a bunch of times while trying to activate Office 2010, I’ve been able to work around the problem by using the telephone activation option provided by Microsoft but it’s a pain and takes about 5 minutes. I honestly can’t believe I’ve put up with problem for so long when the solution to my problem was fairly obvious and straight forward.

If you are dealing with this error try running the activation as Administrator (right click Word or Excel and select Run as Administrator)

Worked first time for me.


Tuesday, 14 October 2014

Outlook 2013 New Feature

I’ve started upgrading a few people from Outlook 2007/2010 to 2013 and have come across a new feature that’s really going to help out some of my users.

Some of my users have mammoth mailboxes, one in particular is at 20GB. Outlook in cached mode routinely slows up and the only explanation that we can reach is that Outlook must be doing some routine maintenance on the OST. It became so unusable that we turned off cached mode for that user. The answer is to obviously delete and archive email but some users are stubborn.

We did switch off Outlook caching, but now we find that when the user is going in and out of folders etc that Outlook will hang for a few seconds, its quite frustrating.


Anyway onto Outlook 2013, under account settings there is a now a slider titled “Mail to keep offline” it ranges from 1 month, 3 months, 6 months, 12 months and all. 

Monday, 13 October 2014

VB.NET: How to sort listview by clicked column

Ok, I claim no credit for this whatsoever, but just in case Fryan Valdez ever takes down his blog I'll repost the information in his blog post here:

Please click through to read the original blog, I provide a copy of it here purely for my information and future reference

http://www.fryan0911.com/2009/05/vbnet-how-to-sort-listview-by-clicked.html

To make your ListView application capable of column sorting, follow these steps:

1. On your existing project, add a new class with following code:

Public Class clsListviewSorter ' Implements a comparer
    Implements IComparer
    Private m_ColumnNumber As Integer
    Private m_SortOrder As SortOrder
    Public Sub New(ByVal column_number As Integer, ByVal sort_order As SortOrder)
        m_ColumnNumber = column_number
        m_SortOrder = sort_order
    End Sub
    ' Compare the items in the appropriate column
    Public Function Compare(ByVal x As Object, ByVal y As Object) As Integer Implements System.Collections.IComparer.Compare
        Dim item_x As ListViewItem = DirectCast(x, ListViewItem)
        Dim item_y As ListViewItem = DirectCast(y, ListViewItem)
        ' Get the sub-item values.
        Dim string_x As String
        If item_x.SubItems.Count <= m_ColumnNumber Then
            string_x = ""
        Else
            string_x = item_x.SubItems(m_ColumnNumber).Text
        End If
        Dim string_y As String
        If item_y.SubItems.Count <= m_ColumnNumber Then
            string_y = ""
        Else
            string_y = item_y.SubItems(m_ColumnNumber).Text
        End If
        ' Compare them.
        If m_SortOrder = SortOrder.Ascending Then
            If IsNumeric(string_x) And IsNumeric(string_y) Then
                Return Val(string_x).CompareTo(Val(string_y))
            ElseIf IsDate(string_x) And IsDate(string_y) Then
                Return DateTime.Parse(string_x).CompareTo(DateTime.Parse(string_y))
            Else
                Return String.Compare(string_x, string_y)
            End If
        Else
            If IsNumeric(string_x) And IsNumeric(string_y) Then
                Return Val(string_y).CompareTo(Val(string_x))
            ElseIf IsDate(string_x) And IsDate(string_y) Then
                Return DateTime.Parse(string_y).CompareTo(DateTime.Parse(string_x))
            Else
                Return String.Compare(string_y, string_x)
            End If
        End If
    End Function
End Class
2. Declare a private variable on the form where the listview you want to be sorted is located.

Private m_SortingColumn As ColumnHeader

3. Then on the listview's ColumnClick event, add the following code

Private Sub ListView1_ColumnClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.ColumnClickEventArgs) Handles ListView1.ColumnClick
        ' Get the new sorting column.
        Dim new_sorting_column As ColumnHeader = ListView1.Columns(e.Column)
        ' Figure out the new sorting order.
        Dim sort_order As System.Windows.Forms.SortOrder
        If m_SortingColumn Is Nothing Then
            ' New column. Sort ascending.
            sort_order = SortOrder.Ascending
        Else ' See if this is the same column.
            If new_sorting_column.Equals(m_SortingColumn) Then
                ' Same column. Switch the sort order.
                If m_SortingColumn.Text.StartsWith("> ") Then
                    sort_order = SortOrder.Descending
                Else
                    sort_order = SortOrder.Ascending
                End If
            Else
                ' New column. Sort ascending.
                sort_order = SortOrder.Ascending
            End If
            ' Remove the old sort indicator.
            m_SortingColumn.Text = m_SortingColumn.Text.Substring(2)
        End If
        ' Display the new sort order.
        m_SortingColumn = new_sorting_column
        If sort_order = SortOrder.Ascending Then
            m_SortingColumn.Text = "> " & m_SortingColumn.Text
        Else
            m_SortingColumn.Text = "< " & m_SortingColumn.Text
        End If
        ' Create a comparer.
        ListView1.ListViewItemSorter = New clsListviewSorter(e.Column, sort_order)
        ' Sort.
        ListView1.Sort()
    End Sub





Tuesday, 24 June 2014

Working with Regex

If you ever have to work with regular expression then I recommend testing your expressions on this website.

Friday, 20 June 2014

PHP Upload Limits on GoDaddy PHP5.ini


I developed a health and safety document management website which has been running without a hitch for around a month now. I had intentionally set file size limits to be 10MB and decided I would increase this limit as and when larger documents appear. Today a user was hitting an error with a 17MB document. I made all the changes necessary to my source code and put the change live, only for the user to report back that they received an error. Straight away I tried a 12MB document and it worked, I asked how big the file the user was trying and they told me 17MB. I did some research on the error message.

Fatal error: Allowed memory size of 67108864 bytes exhausted”

A lot of results for that error message. I managed to find some tutorials on how to resolve the issue on GoDaddy. Unfortunately the information I found is outdated (or at least no longer applicable to hosting package I am on)

The articles suggest creating a php5.ini on the root directory adding the following configuration:

file_uploads = On
post_max_size = 128M
upload_max_filesize = 128M
memory_limit = 128M


However after speaking with GoDaddy support this is no longer correct (at least not for those on the Economy Linux Hosting with cPanel package)


To resolve the issue you must create a .users.ini file. 

Tuesday, 3 June 2014

Download Office / Visio 2013 offline installer

The network connection at our office is horrible, it’s a long story with very little light at the end of the tunnel. I have purchased a number of copies of Visio 2013, however software these days doesn’t seem to come with an installation CD any more. After registering the product key with Microsoft I was a little miffed to find that the installer they provide you with is only 900KB in size, clearly it was going to download the rest of the application in the background. Not great when I will have to repeat the install several times over.

This took me a while to find but it is possible to download an offline install for your Microsoft Office products.

Browse to office.microsoft.com
Login to your account
Click Install Office
Click install from a disc
Click I want to burn a disc
Click Download





The download file is 2GB in size, I am not sure if this is JUST for Visio or if it includes other Office products that will be filtered by the product key. 

Friday, 16 May 2014

SpaceSniffer - another useful application

 Stop the presses! I can’t believe in all the time that this blog has been going that I haven’t once mentioned or credited an application that I've used countless times.



SpaceSniffer (http://www.uderzo.it/main_products/space_sniffer/) is freeware so what’s not to love? SpaceSniffer provides you with a visual representation of folders / file sizes on your hard drive. Today I ran out of disk space, I ran SpaceSniffer and managed to recover 30GB that was hiding in SQL Express (a database I had restored for testing and a transaction log file). It’s simple and intuitive to use.

Wednesday, 16 April 2014

Spam

I have a strange fascination with Spam, its something that really intrigues me. I felt like I just had to post the following bit of spam I received. It didn't ask me to click to verify my bank account details, there was no attachment (with a virus) and it doesn't seem to be trying to sell me anything. It appears to be a combination of random sentences taken from Wikipedia.

It makes so little sense that it actually made me smile.

"After we wrote it, we thought it sounds just like a Blake Shelton song. Also Puerto Cabello was at that time under Dutch control. It is simply a short length of material worn around the thighs rather like a sarong."

Tuesday, 15 April 2014

MySQL migration to MSSQL

I use a mix of database servers depending on what application / project I am working on, normally it will be either SQL Server (inc Express) or MySQL.

I find working with SQL statements in SQL Server Management Studio to be much easier than creating statements on the fly, so its useful to have a copy of the MySQL databases on my MSSQL server, previously I have manually created a new database with the tables / structure that I need to create my SQL statements.

That all changed when I came across Intelligent Converters (http://www.convert-in.com/)  They have a great bit of software that will copy databases from just about anything to anything, in this case MySQL to MSSQL (http://www.convert-in.com/sql2mss.htm) The trial version of the software is limited to copying only 5 records per table, that's perfect if you just want the structure of the tables, for $49 you can have the full version of the software and for $99 you can get the MySQL Migration Toolkit which will convert any data source to or from MySQL.

SQL Backup And FTP

Since moving to SQL Server 2005/2008 (including SQL Express at home) I've been using SQL Server Management Studio to create a daily database backup. In my home environment my databases are very small (mostly development projects) so I place these backups into a folder than is configured to synchronize with the cloud. I'm not too worried about full server backups as the database server has minimal configuration done to it. In my business environments I have daily backups that backup the full system (including my SQL backup files). 

Despite using the Management Studio for nearly 9 years now I know very little about it, so perhaps it has the functionality built within it and I just don't process the knowledge (nor did my search results) on how to backup SQL databases to a network location, I also wasn't really in the mood to go fiddling with scripts etc.

I came across a great bit of software called SQL Backup And FTP (http://sqlbackupandftp.com/) 

The most basic (free) version of the software has a lot of functionality and setting up a job is easy.  

Friday, 11 April 2014

Add Header logo / image to blogger

Not sure how I missed this when I created this new blog but adding an image to your blog header is a lot easier than I first thought. I searched for how to do it and a number of people suggested adding a image widget but it turns out Blogger has already provided the functionality to do this.

1) Select Layout
2) On the header click Edit
3) Select your header image and options

Thursday, 10 April 2014

GoDaddy PHPMailer Relay problems

This has been very frustrating, if you search for GoDaddy and PHPMailer you'll find loads of posts about how PHPMailer needs to be configured in order to work with GoDaddy's hosting.

I tried using some of the configuration information I found online but I wasn’t having any luck. I kept getting “Error: The following From address failed:” despite trying several different addresses (including valid addresses that I had setup on GoDaddy’s cPanel)

I finally came across Aravind is Online blog which nudged me in the right direction (http://aravindisonline.blogspot.co.uk/2012/01/phpmailer-with-godaddy-smtp-email.html)

For completeness.
You cannot use an external host to relay email messages. You must use the following host: relay-hosting.secureserver.net  

I setup a mail user specifically for PHPMailer (I am hosting a subdomain so all my email services are elsewhere)

Use PORT 25 (numerous guides suggest 465)


Set SMTP Auth to true, Aravind’s guide suggests to set this to false, however this didn’t work for me.