IT Skills

IT Skills

This blog is for IT lovers, accounts and finance executives who want to add value in their professional life.

test

Breaking

Welcome to our blog. This blog is for IT lovers, Accounts/Finance Executives who wants to add value in their career path.

Search This Blog

Monday, 25 June 2018

SQL Series...45

June 25, 2018 0
SQL Series...45
test

Using GRANT and REVOKE Together Saves Time and Effort


Multiple privileges for multiple users on selected table columns may require a lot of typing. Consider this example: The vice president of sales wants everyone in sales to see everything in the CUSTOMER table. But only sales managers should update, delete, or insert rows. Nobody should update the CustID field. The sales managers’ names are Tyson, Keith, and David. You can grant appropriate privileges to these managers with GRANT statements, as follows:

GRANT SELECT, INSERT, DELETE


ON CUSTOMER
TO Tyson, Keith, David ;
GRANT UPDATE
ON CUSTOMER (Company, CustAddress, CustCity,
CustState, CustZip, CustPhone, ModLevel)

TO Tyson, Keith, David ;
GRANT SELECT
ON CUSTOMER
TO Jenny, Valerie, Melody, Neil, Robert, Sam,
Brandon, MichelleT, Allison, Andrew,
Scott, MichelleB, Jaime, Linleigh, Matthew, Amanda;

That should do the trick. Everyone has SELECT rights on the CUSTOMER table. The sales managers have full INSERT and DELETE rights on the table, and they can update any column but the CustID column. Here’s an easier way to get the same result:

GRANT SELECT


ON CUSTOMER
TO SalesReps ;
GRANT INSERT, DELETE, UPDATE
ON CUSTOMER
TO Tyson, Keith, David ;
REVOKE UPDATE
ON CUSTOMER (CustID)
FROM Tyson, Keith, David ;

You still take three statements in this example for the same protection of the three statements in the preceding example. No one may change data in the CustID column; only Tyson, Keith, and David have INSERT, DELETE, and UPDATE privileges. These latter three statements are significantly shorter than those in the preceding example because you don’t name all the users in the sales department and all the columns in the table. (The time you spend typing names is also significantly shorter. That’s the idea.)

VBA Programming Series...46

June 25, 2018 0
VBA Programming Series...46
test

Events Not Associated with Objects


The events that I discuss previously in the articles are associated with either a workbook object or a worksheet object. Now, I discuss two types of events that are not associated with objects: time and keypresses.


Because time and keypresses aren’t associated with a particular object such as a workbook or a worksheet, you program these events in a normal VBA module.
The OnTime event

The OnTime event occurs when a particular time of day occurs. The follow-ing example demonstrates how to get Excel to execute a procedure when the 3:00 p.m. event occurs. In this case, a robot voice tells you to wake up, accompanied by a message box:


Sub SetAlarm()
Application.OnTime 0.625, “DisplayAlarm”
End Sub

Sub DisplayAlarm()
Application.Speech.Speak (“Hey, wake up”)
MsgBox “ It’s time for your afternoon break!”
End Sub

In this example, I use the OnTime method of the Application object. This method takes two arguments: the time (0.625 or 3:00 p.m.) and the name of the Sub procedure to execute when the time event occurs (DisplayAlarm).

This procedure is quite useful if you tend to get so wrapped up in your work that you forget about meetings and appointments. Just set an OnTime event to remind yourself.


Most people (this author included) find it difficult to think of time in terms of the Excel numbering system. Therefore, you may want to use the VBA TimeValue function to represent the time. TimeValue converts a string that looks like a time into a value that Excel can handle. The following statement shows an easier way to program an event for 3:00 p.m.:


Application.OnTime TimeValue(“3:00:00 pm”), “DisplayAlarm”

If you want to schedule an event relative to the current time — for example, 20 minutes from now — you can use a statement like this:


Application.OnTime Now + TimeValue(“00:20:00”),
“DisplayAlarm”

You can also use the OnTime method to run a VBA procedure on a particular day. You must make sure that your computer keeps running and that the workbook with the procedure is kept open. The following statement runs the DisplayAlarm procedure at 5:00 p.m. on December 31, 2010:


Application.OnTime DateValue(“12/31/2010 5:00 pm”), _
“DisplayAlarm”
This particular code line could come in handy to warn you that you need to go home and get ready for the New Year’s Eve festivities.

Here’s another example that uses the OnTime event. Executing the UpdateClock procedures writes the time to cell A1 and also programs another event five seconds later. This event reruns the UpdateClock proce-dure. The net effect is that cell A1 is updated with the current time every five seconds. To stop the events, execute the StopClock procedure (which can-cels the event). Note that NextTick is a module-level variable that stores the time for the next event.


Dim NextTick As Date

Sub UpdateClock()

‘ Updates cell A1 with the current time ThisWorkbook.Sheets(1).Range(“A1”) = Time

‘ Set up the next event five seconds from now NextTick = Now + TimeValue(“00:00:05”) Application.OnTime NextTick, “UpdateClock”
End Sub

Sub StopClock()

‘ Cancels the OnTime event (stops the clock) On Error Resume Next

Application.OnTime NextTick, “UpdateClock”, , False End Sub

The OnTime event persists even after the workbook is closed. In other words, if you close the workbook without running the StopClock procedure, the work-book will reopen itself in five seconds (assuming that Excel is still running). To prevent this, use a Workbook_BeforeClose event procedure that contains the following statement:

Call StopClock


The OnTime method has two additional arguments. If you plan to use this method, you should refer to the online help for complete details.

If you’d like to see a rather complicated application, download a copy of my analog clock workbook, shown in Figure 11-6. The clock face is actually a chart, and the chart is updated every second to display the time of day. Useless, but fun.

Keypress events


While you work, Excel constantly monitors what you type. Because of this, you can set up a keystroke or a key combination to execute a procedure.

Here’s an example that reassigns the PgDn and PgUp keys:


Sub Setup_OnKey()
Application.OnKey “{PgDn}”, “PgDn_Sub”
Application.OnKey “{PgUp}”, “PgUp_Sub”
End Sub

Sub PgDn_Sub()
On Error Resume Next
ActiveCell.Offset(1, 0).Activate
End Sub

Sub PgUp_Sub()
On Error Resume Next
ActiveCell.Offset(-1, 0).Activate
End Sub

After setting up the OnKey events by executing the Setup_OnKey procedure, pressing PgDn moves you down one row. Pressing PgUp moves you up one row.

Notice that the key codes are enclosed in braces, not in parentheses. For a complete list of keyboard codes, consult the Help system. Search for OnKey.
In this example, I use On Error Resume Next to ignore any errors that are gen-erated. For example, if the active cell is in the first row, trying to move up one row causes an error that can safely be ignored. And if a chart sheet is active, there is no active cell.

By executing the following routine, you cancel the OnKey events:


Sub Cancel_OnKey()
Application.OnKey “{PgDn}”
Application.OnKey “{PgUp}”
End Sub

Using an empty string as the second argument for the OnKey method does not cancel the OnKey event. Rather, it causes Excel to simply ignore the key-stroke. For example, the following statement tells Excel to ignore Alt+F4. The percent sign represents the Alt key:


Application.OnKey “%{F4}”, “”


Although you can use the OnKey method to assign a shortcut key for execut-ing a macro, you should use the Macro Options dialog box for this task.

If you close the workbook that contains the code and leave Excel open, the OnKey method will not be reset. As a consequence, pressing the shortcut key will cause Excel to automatically open the file with the macro. To prevent this from happening, you should include code in your Workbook_BeforeClose event code to reset the Onkey event.


Sunday, 24 June 2018

IT Tips and Tricks Series...61

June 24, 2018 0
IT Tips and Tricks Series...61
test

Paste text without formatting

When referring to rich-text, like found on a web page, Word document, or e-mail, the formattingremains when it is copied then pasted elsewhere. For example, if you were to copy this paragraph of text, "This is bold" would remain bold when you paste it into any other document that supports rich-text. Anyone needs plain text pasting frequently may find having a universal shortcut key beneficial.

Free Software

We recommend the free tool PureText, which runs in the background and can paste plain text into any program using the same shortcut key your choosing (Windows key + V by default). PureText is capable of removing font faces, font styles (i.e. bold, italic, etc.), font colors, paragraph styles, extra spacing, tables, and pictures from any text you copy.

Download PureText

Windows Tip: 

In most versions of Windows Ctrl+Windows Key + V also pastes text as plain text.

SQL Series...44

June 24, 2018 0
SQL Series...44
test

Taking Privileges Away


If you have a way to give access privileges to people, you better also have a way of taking those privileges away. People’s job functions change, and with these changes, their need for access to data changes. People may even leave the organization to join a competitor. You should probably revoke all the access privileges of such people. SQL provides for the removal of access privileges by using the REVOKE statement. This statement acts like the GRANT statement does, except that it has the reverse effect. The syntax for this statement is as follows:


REVOKE [GRANT OPTION FOR] privilege-list

ON object
FROM user-list [RESTRICT|CASCADE] ;

You can use this structure to revoke specified privileges while leaving others intact. The principal difference between the REVOKE statement and the GRANT statement is the presence of the optional RESTRICT or CASCADE keyword in the REVOKE statement. If you used WITH GRANT OPTION to grant the privi-leges you’re revoking, using CASCADE in the REVOKE statement revokes privi-leges for the grantee and also for anyone to whom that person granted those privileges as a result of the WITH GRANT OPTION clause. On the other hand, the REVOKE statement with the RESTRICT option works only if the grantee hasn’t delegated the specified privileges. In the latter case, the REVOKE state-ment revokes the grantee’s privileges. If the grantee passed on the specified privileges, the REVOKE statement with the RESTRICT option doesn’t revoke anything and instead returns an error code.


You can use a REVOKE statement with the optional GRANT OPTION FOR clause to revoke only the grant option for specified privileges while enabling the grantee to retain those privileges for himself. If the GRANT OPTION FOR clause and the CASCADE keyword are both present, you revoke all privileges that the grantee granted, along with the grantee’s right to bestow such privi-leges — as if you’d never granted the grant option in the first place. If the GRANT OPTION FOR clause and the RESTRICT clause are both present, one of two things happens:


If the grantee didn’t grant to anyone else any of the privileges you’re revoking, then the REVOKE statement executes and removes the grantee’s ability to grant privileges.

If the grantee has already granted at least one of the privileges you’re revoking, the REVOKE doesn’t execute and returns an error code instead.


The fact that you can grant privileges by using WITH GRANT OPTION, com-bined with the fact that you can also selectively revoke privileges, makes system security much more complex than it appears at first glance. Multiple grantors, for example, can conceivably grant a privilege to any single user. If one of those grantors then revokes the privilege, the user still retains that privilege because of the still-existing grant from another grantor. If a privilege passes from one user to another by way of the WITH GRANT OPTION, this sit-uation creates a chain of dependency, in which one user’s privileges depend on those of another user. If you’re a DBA or object owner, always be aware that, after you grant a privilege by using the WITH GRANT OPTION clause, that privilege may show up in unexpected places. Revoking the privilege from unwanted users while letting legitimate users retain the same privilege may prove challenging. In general, the GRANT OPTION and CASCADE clauses encompass numerous subtleties. If you use these clauses, check both the SQL:2003 standard and your product documentation carefully to ensure that you understand how the clauses work.


VBA Programming Series...45

June 24, 2018 0
VBA Programming Series...45
test

Other Worksheet-Related Events


In the preceding section, I present examples for worksheet activation and deactivation events. In this section, I discuss three additional events that occur in worksheets: double-clicking a cell, right-clicking a cell, and changing a cell.

The BeforeDoubleClick event


You can set up a VBA procedure to be executed when the user double-clicks a cell. In the following example (which is stored in the Code window for a Sheet object), double-clicking a cell in that sheet makes the cell bold (if it’s not bold) or not bold (if it is bold):


Private Sub Worksheet_BeforeDoubleClick _
(ByVal Target As Excel.Range, Cancel As Boolean)
Target.Font.Bold = Not Target.Font.Bold
Cancel = True
End Sub

The Worksheet_BeforeDoubleClick procedure has two arguments: Target and Cancel. Target represents the cell (a Range object) that was double-clicked. If Cancel is set to True, the default double-click action doesn’t occur.

The default action for double-clicking a cell is to put Excel into cell edit mode.

I didn’t want that to happen, so I set Cancel to True.

The BeforeRightClick event



The BeforeRightClick event is similar to the BeforeDoubleClick event, except that it consists of right-clicking a cell. The following procedure checks to see whether the cell that was right-clicked contains a numeric value. If so, the
code displays the Format Number dialog box and sets the Cancel argument to True (avoiding the normal shortcut menu display). If the cell does not contain a numeric value, nothing special happens — the shortcut menu is displayed as usual.


Private Sub Worksheet_BeforeRightClick _
(ByVal Target As Excel.Range, Cancel As Boolean)
If IsNumeric(Target) And Not IsEmpty(Target) Then
Application.CommandBars.ExecuteMso _
(“NumberFormatsDialog”)
Cancel = True
End If
End Sub


This is because VBA considers empty cells to be numeric. Don’t ask me why; it just does.

The Change event


The Change event occurs whenever any cell on the worksheet is changed. In the following example, the Worksheet_Change procedure effectively prevents a user from entering a nonnumeric value into cell A1. This code is stored in the Code window for a Sheet object.


Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Address = “$A$1” Then
If Not IsNumeric(Target) Then
MsgBox “Enter a number in cell A1.”
Range(“A1”).ClearContents
Range(“A1”).Activate
End If
End If
End Sub

The single argument for the Worksheet_Change procedure (Target) repre-sents the range that was changed. The first statement sees whether the cell’s address is $A$1. If so, the code uses the IsNumeric function to determine whether the cell contains a numeric value. If not, a message appears, and the cell’s value is erased. Cell A1 is then activated — useful if the cell pointer moved to a different cell after the entry was made. If the change occurs in any cell except A1, nothing happens.

Why not use data validation?

You may be familiar with the Data➪Data Tools➪Data Validation com-mand. This is a handy feature that makes it easy to ensure that only data of the proper type is entered into a particular cell or range. Although the
Data➪Data Tools➪Data Validation command is useful, it’s definitely not foolproof. To demonstrate, start with a blank worksheet and perform the following steps:

1. Select the range A1:C12.

2. Choose Data➪Data Tools➪Data Validation.

3. Set up your validation criteria to accept only whole numbers between 1 and 12, as shown in Figure 11-5.
Now, enter some values in the range A1:C12. The data validation works as it should. But to see it fall apart at the seams, try this:

1. Enter –1 into any cell outside the validation range (any cell not in

A1:C12).

2. Press Ctrl+C to copy the negative number to the Clipboard.

3. Select any cell in the validation range.

4. Press Ctrl+V to paste the copied value.

You find that the paste operation is allowable. Look a little closer, however, and you find that the cell into which you pasted the negative value no longer has any validation criteria. Pasting wipes out the data validation criteria!

The severity of this flaw depends on your application. In the next section, I describe how to use the Change event to provide for better validating.

Pasting wipes out data validation because Excel considers validation a format for a cell. Therefore, it is in the same classification as font size, color, or other similar attributes. When you paste a cell, you are replacing the formats in the target cell with those of the source cell. Unfortunately, those formats also include your validation rules.

Preventing data validation from being destroyed


The procedure in this section demonstrates how to prevent users from copy-ing data and wiping out data validation rules. This example assumes that the worksheet has a range named InputArea, and this input area contains data validation rules (set up by using the Data➪Data Tools➪Data Validation com-mand). The range can have any validation rules you want.


Private Sub Worksheet_Change(ByVal Target As Range)
Dim VT As Long
‘Do all cells in the validation range
‘still have validation?
On Error Resume Next
VT = Range(“InputRange”).Validation.Type
If Err.Number <> 0 Then
Application.Undo

MsgBox “Your last operation was canceled.” & _ “It would have deleted data validation rules.”, _ vbCritical

End If
End Sub

The procedure is executed whenever a cell is changed. It checks the valida-tion type of the range (named InputRange) that is supposed to contain the data validation rules. If the VT variable contains an error, that means that one or more cells in the InputRange no longer have data validation (the user probably copied some data over it). If that’s the case, the code executes the Undo method of the Application object and reverses the user’s action. Then it displays a message box.

The net effect? It’s impossible to wipe out the validation rules by copying data. When Excel is broken, use VBA to fix it.

Saturday, 23 June 2018

IT Tips and Tricks Series...60

June 23, 2018 0
IT Tips and Tricks Series...60
test

Create a presentation slide show online

There are several online solutions that allow you to create a slide show presentation without having to install any programs or buy expensive solutions like Microsoft Power Point. Try any of the below suggestions.

Presentation slide show

If you want to create an online presentation, something that you can show to co-workers, a meeting, or a conference try any of the online services below.
Prezi
Slides
Google Slides

Photo slide show

If you're wanting to create a slide show of only photos, something you'd show to your family, friends, or co-workers try one of the online services below.
Slidely
Kizoa

SQL Series...43

June 23, 2018 0
SQL Series...43
test

Granting the Power to Grant Privileges

The DBA can grant any privileges to anyone. An object owner can grant any privileges on that object to anyone. But users who receive privileges this way can’t in turn grant those privileges to someone else. This restriction helps the DBA or table owner retain control. Only users the DBA or object owner empowers to do so can gain access to the object in question.

From a security standpoint, putting limits on the capability to delegate access privileges makes a lot of sense. Many occasions arise, however, in which users need such delegation authority. Work can’t come to a screeching halt every time someone is ill, on vacation, or out to lunch. You can trust some users with the power to delegate their access rights to reliable desig-nated alternates. To pass such a right of delegation to a user, the GRANT uses the WITH GRANT OPTION clause. The following statement shows one example of how you can use this clause:


GRANT UPDATE (BonusPct)

ON BONUSRATE
TO SalesMgr
WITH GRANT OPTION ;

Now the sales manager can delegate the UPDATE privilege by issuing the following statement:
GRANT UPDATE (BonusPct)

ON BONUSRATE
TO AsstSalesMgr ;

After the execution of this statement, the assistant sales manager can make changes to the BonusPct column in the BONUSRATE table — a power she didn’t have before.


A tradeoff exists between security and convenience. The owner of the BONUSRATE table relinquishes considerable control in granting the UPDATE privilege to the sales manager by using the WITH GRANT OPTION. The table owner hopes that the sales manager takes this responsibility seriously and is careful about passing on the privilege.


Popular

Welcome to our blog. If you want to; learn writing skills, preparation for CSS/Corporate laws, IT skills, downloading Business/IT books, and many more; this blog is for you.