Friday, 16 December 2011

Nullable DateTimePicker control

In this blog I will show you how to modify DateTimePicker control to support data binding to Nullable dataset field. Usually when we want to bind a DateTimePicker to a Datetime field we use the following command:

   DateTimePicker1.DataBindings.Add(new Binding("Value", ds, customers.CustToOrders.OrderDate"));

The problem with this control is that : The Value  property is a DateTime  type and they cannot be assigned to null literal.

To workarround this problem I create my own DateTimePicker drived from the real one. and I override Value property using String as the new type. Because string can be assigned to null and can convert easily between string and DateTime types.

Here is the class:

    /// <summary>
    /// Summary description for DateTimePicker.
    /// </summary>

    public class DateTimePickerCustom : System.Windows.Forms.DateTimePicker
    {
        private DateTimePickerFormat oldFormat = DateTimePickerFormat.Long;
        private string oldCustomFormat = null;
        private bool bIsNull = false;


        public DateTimePickerCustom()
            : base()
        {
        }

        public new String Value
        {

            get
            {
                if (bIsNull)
                    return null;
                else
                    return base.Value.ToString("yyyy-MM-dd");
            }

            set
            {

                if ((value == null)  || (value == DBNull.Value.ToString()))
                {

                    if (!bIsNull)                    {
                        base.Value = base.MinDate;
                        oldFormat = this.Format;
                        oldCustomFormat = this.CustomFormat;
                        bIsNull = true;
                        this.Format = DateTimePickerFormat.Custom;
                        this.CustomFormat = " ";
                    }

                }
                else
                {
                    if (bIsNull)

                    {
                        this.Format = oldFormat;                       

                        this.CustomFormat = oldCustomFormat;
                    }
                    bIsNull = false;
                    base.Value = DateTime.Parse(value);
                }
            }
         }
     }
}

Monday, 31 October 2011

CallBack function with VBA

This post shows you how to implement a CallBack function with VBA.

There is no way to implement a callback function in VBA wihout creating an API  in C (Dynamic Library Link).

Create Win32 Dynamic Library Link Project with VC++
  1. Start VC++ IDE ,
  2. Select New from File menu.  Then select Win32 Dynamic - link library from Projects tab.
  3. Enter project name as "CallBackFuncApi"
  4. then click OK button, Now you can see a dialog box with caption Win32 Dynamic - Link library - step 1 of 1
  5. Select An Empty DLL project , and click Finish.
  6. Create the follwing files cb.h , cb.cpp and cb.def
/***  cb.h file ***/
#define EXTERNC extern "C"
#define DLLAPI __declspec(dllexport)
#define WINAPI __stdcall


typedef bool (CALLBACK *CallbackFunc) (VARIANT userData);


EXTERNC DLLAPI DWORD WINAPI CallBackFuncVariantHndl(CallbackFunc pCallback);


/*** cb.cpp ***/
#include <windows.h>
#include "cb.h"


EXTERNC DLLAPI void WINAPI CallBackFuncVariantHndl(CallbackFunc pCallback, VARIANT userData)
{
 (*pCallback)(userData);
}
}
/*** cb.def ***/
EXPORTS
CallBackFuncVariantHndl

Using CallBack function api with VBA
You have to copy CallBackFuncApi.Dll into system32 folder

Public Declare Function CallBackFuncVariantHndl Lib "CallBackFuncApi" (ByVal pCallback As Long) As Long

'Call back function with variant parameter (should be in Module)
Public Sub MyCallBackFunction(ByVal vnt As Variant)
  ' Enter your code
End Sub
'
Public Sub MyCallBackFunction(ByVal vnt As Variant)
Dim  vnt As Variant
vnt = split("Item 1 - Item 2 - Item 3 ","-") 
Call CallBackFuncVariantHndl (AddressOf  MyCallBackFunction, vnt)
End Sub

Saturday, 3 September 2011

Run a recovery disc for TOSHIBA Laptop

A portion of your notebook computer's hard disk is reserved to hold recovery data. If the files preinstalled on the primary partition become damaged, you can use hard disk drive recovery to restore them. If the recovery data is also damaged, you can use CD or DVD recovery media to restore the preinstalled files. Recovery media are not included with your notebook computer, and are not available from Toshiba. You can create CD or DVD recovery media from the recovery data by clicking on the “Recovery Disc Creator” icon on the desktop.

To restore the operating system and all preinstalled software using Hard Drive Recovery follow the steps below.   (Applicable Models Only)   
1.     Make sure the laptop is powered “OFF”.  
2.     Press and hold the “0” zero key while powering on the laptop.
3.     Release the “0” key when “Hard Drive Recovery mode” message
4.     Follow the on-screen instructions.



Friday, 12 August 2011

Adding a Paypal Donation Button to your Blogger blog

This is post show you step by step how you can add a Paypal Donation Button to your blog.


Create a Paypal Donation Button
  1. If you don't have Paypal account  you can get one for free.
  2. Log into your Paypal account
  3. Click on "Merchant Services" tab in the Top Menu
  4. Scroll down to "Create buttons" section
  5. Clicking on the "Donate" link will take you a form where you are asked to fill some information’s like Organization name/service, Donation ID (optional).
  6. After Filing the required information click on ‘Create Button’ link.
  7. Now you will see some HTML Code, copy it
Adding HTML code into Blogger free blogs:
  1. Sign in into your Blogger Blog and Click on the ‘Design’ link in your dashboard
  2. Click ‘Add a Gadget’ link and select ‘HTML/JavaScript’ option
  3. Now paste the HTML code that you copied from your Paypal account and save it.
  4. Now open your blog and you will see the ‘Paypal Donate’ button in your blogspot blog sidebar. You can display Donate button wherever you want on your blog like blog Header, footer or its sidebar

Tuesday, 9 August 2011

Ms-Access Free books

Microsoft Access 2007 Data Analysis



Chart a course for more effective data analysis with Access 2007. With this resource, you’ll learn how Access 2007 offers powerful functionality that may be better suited to your data analysis needs. Learn to analyze large amounts of data in meaningful ways, quickly and easily slice it into various views, automate redundant analysis, and save time—all using Access. If you know a bit about table structures and formulas as well as data analysis, start thinking outside the chart.


Download: http://rapidshare.com/files/110044369/ac2o7datan.rar
                   http://www.mediafire.com/?77njv4579594v7t   (pdf format)

Wednesday, 27 July 2011

Open source Content Management system

What's a CMS
**From Wikipedia**
     A web content management system (WCMS) is a software system that provides website authoring, collaboration, and administration tools designed to allow users with little knowledge of web programming languages or markup languages to create and manage website content with relative ease. A robust WCMS provides the foundation for collaboration, offering users the ability to manage documents and output for multiple author editing and participation.
Most systems use a database to store page content, metadata, and other information assets that might be needed by the system.
A presentation layer displays the content to website visitors based on a set of templates. The templates are sometimes XSLT files.[1]
Most systems use server side caching to improve performance. This works best when the WCMS is not changed often but visits happen regularly.
Administration is typically done through browser-based interfaces, but some systems require the use of a fat client.
A WCMS allows non-technical users to make changes to a website with little training. A WCMS typically requires a systems administrator and/or a web developer to set up and add features, but it is primarily a website maintenance tool for non-technical staff.

Some popular CMS
Joomla,e107 and Drupal are  the most popular  open source Content Management System. They are
 completly free, customisable and in constant development.

Drupal: http://drupal.org/
Joomla: http://www.joomla.org/
e107:  http://e107.org/

LINKS:

Wednesday, 20 July 2011

MS ACCESS: Create a dynamic menu with SwitchBoard table

The following example demonstrates how to create a dynamic menu based on SwitchBoard table contente.

Step 1. Create a custom toolbar
  1. On the Tools menu, click Customize.
  2. Click the Toolbars tab.
  3. Click New.
  4. In the Toolbar name box, type the name you want (ex. MyCustMenuBar), and then click OK.
  5. Click the properties button.
  6. Set Type to Menu Bar
Step 2. Class Modules clsMenu

Option Compare Database
Option Explicit

Const cTOOLBAR = "MyCustMenuBar"
Const cMACRO = "=MenuHandle () "

' Constants for the commands that can be executed. 
 Public Const conCmdGotoSwitchboard = 1
 Public Const conCmdOpenFormAdd = 2
 Public Const conCmdOpenFormBrowse = 3
 Public Const conCmdOpenReport = 4
 Public Const conCmdCustomizeSwitchboard = 5
 Public Const conCmdExitApplication = 6
 Public Const conCmdRunMacro = 7
 Public Const conCmdRunCode = 8
 Public Const conCustomizeMenu = 9


Public Function FillSubMenu(SwitchboardID As Long, menuSelected As Object) As Boolean
    Dim rst As Recordset
    Dim intOption As Integer
    Dim ctl As CommandBarControl
    'Clear menu   

   For Each ctl In menuSelected.Controls
        Call ctl.Delete
    Next


    ' If there are no options for this Switchboard Page,
    ' display a message.  Otherwise, fill the page with the items.
   
    Set rst = Me.GetMenuOptions(SwitchboardID)
   
    If (rst.EOF) Then
        MsgBox ("There are no items for this switchboard page")
    Else
        While (Not (rst.EOF))
            Dim newMenu As CommandBarControl
           
            If (SwitchboardID = 1) Then
                    Set newMenu = menuSelected.Controls.Add(Type:=msoControlPopup)
            Else
                Select Case rst!Command
                 Case conCmdGotoSwitchboard
                     Set newMenu = menuSelected.Controls.Add(Type:=msoControlPopup)
                 Case conCustomizeMenu
                     Set newMenu = menuSelected.Controls.Add(Type:=msoControlPopup)
                 Case conCmdRunCode
                    If (rst!Argument = "CreateSLTReportSubMenu") Then
                        Set newMenu = menuSelected.Controls.Add(Type:=msoControlPopup)
                    Else
                        Set newMenu = menuSelected.Controls.Add(Type:=msoControlButton, Temporary:=True)
                    End If
                 Case Else
                     Set newMenu = menuSelected.Controls.Add(Type:=msoControlButton, Temporary:=True)
                 End Select
            End If
            newMenu.Caption = rst![ItemText]
            newMenu.tag = Trim$(str$(SwitchboardID))
            newMenu.OnAction = cMACRO
          
           rst.MoveNext
        Wend
    End If
    ' Close the recordset and the database.   
rst.Close
End Function


Public Function GetMenuOptions(SwitchboardID As Long, Optional mnuGlobal) As Recordset
    Dim strSQL As String
    Dim fixedMenu As String
    If Not IsMissing(mnuGlobal) Then fixedMenu = " OR [SwitchboardID]=" & mnuGlobal
    ' Open the table of Switchboard Items, and find
    ' the first item for this Switchboard Page.
   
    strSQL = "SELECT id, SwitchboardID,ItemNumber, ItemText ,command,Argument"

    strSQL = strSQL & " FROM [Switchboard Items]"
    strSQL = strSQL & " WHERE [ItemNumber] > 0 AND ([SwitchboardID]=" & SwitchboardID & fixedMenu & ")"
    strSQL = strSQL & " ORDER BY SwitchboardID,[ItemNumber];"
   
    Set GetMenuOptions = CurrentDb.OpenRecordset(strSQL)

End Function

Public Function HandleButtonClick(Optional switchmenu, Optional btnid, Optional stdMenu)
' This function is called when a button is clicked.
' intBtn indicates which button was clicked.
   
    Dim dbs As Database
    Dim rst As Recordset
   
    '*****************
    Dim intBtn As Integer
    Dim SwitchboardID As Integer
    Dim isStandardMnu As Boolean
    On Error GoTo HandleButtonClick_Err
   
    ' Le Tag dans le bouton contient le SwitchBoardID
    If IsMissing(switchmenu) Then
        SwitchboardID = CInt(Application.CommandBars.ActionControl.tag)
    Else
         SwitchboardID = switchmenu
    End If
   
    If IsMissing(btnid) Then
        intBtn = Application.CommandBars.ActionControl.Index
    Else
        intBtn = btnid
    End If
   
    ' If the standard menu clicked
    If IsMissing(stdMenu) Then
        isStandardMnu = False
    Else
        isStandardMnu = stdMenu
    End If
  
    ' Find the item in the Switchboard Items table
    ' that corresponds to the button that was clicked.
    Set dbs = CurrentDb()
   
    Set rst = dbs.OpenRecordset("Switchboard Items", dbOpenDynaset)
    rst.FindFirst "[SwitchboardID]=" & SwitchboardID & " AND [ItemNumber]=" & intBtn
   
    lastMenu = rst!ID  'Handle pressed menu id
  
    ' If no item matches, report the error and exit the function.
    If (rst.NoMatch) Then
        MsgBox "There was an error reading the Switchboard Items table."
        rst.Close
        dbs.Close
        Exit Function
    End If
   
    Select Case rst![Command]
       
        ' Go to another switchboard.
        Case conCmdGotoSwitchboard
            If isStandardMnu Then
                 Forms("Switchboard").Filter = "[ItemNumber] = 0 AND [SwitchboardID]=" & rst![Argument]
            Else
                Call Me.FillSubMenu(rst![Argument], Application.CommandBars.ActionControl)
            End If
               
        ' Open a form in Add mode.
        Case conCmdOpenFormAdd
            OpenForm rst![Argument], acNormal, , , acAdd, , -1
        ' Open a form.
        Case conCmdOpenFormBrowse
             OpenForm rst![Argument]
           
        ' Open a report.
        Case conCmdOpenReport
            DoCmd.OpenReport rst![Argument], acPreview
        Case conCmdExitApplication
            CloseCurrentDatabase
        ' open form with paramaters
        Case conCmdOpenFormWithPara
            OpenForm rst![Argument], acNormal, , , , , rst![parameters]
           
        Case conCmdOpenFormAddWthPara
            OpenForm rst![Argument], , , , acFormAdd, , rst![parameters]
        ' Run a macro.
        Case conCmdRunMacro
            DoCmd.RunMacro rst![Argument]
        ' Run code.
        Case conCmdRunCode
            If Nz(rst!parameters, "") = "" Then
                Application.Run rst![Argument]
            Else
                Application.Run rst![Argument], rst!parameters
            End If
        ' Customize Menu
        Case conCustomizeMenu, conRunCustomizeMenu
            Application.Run rst![Argument]
           
        ' Any other command is unrecognized.
        Case Else
         MsgBox "Unknown option."
   
    End Select
    ' Close the recordset and the database.
    rst.Close
    dbs.Close

HandleButtonClick_Exit:
    Exit Function
HandleButtonClick_Err:
    ' If the action was cancelled by the user for
    ' some reason, don't display an error message.
    ' Instead, resume on the next line.
    If (err = conErrDoCmdCancelled) Then
        Resume Next
    Else
        MsgBox ("There was an error executing the command.")
        Resume HandleButtonClick_Exit
    End If
   
End Function

Public Function InitializeMenu()
    Call FillSubMenu(1, Application.CommandBars(cTOOLBAR))
End Function


Step 3. Module MainModule

Public  oMenu As new clsMenu

Public Function MenuHandle() As Boolean
    Call oMenu.HandleButtonClick
    MenuHandle = True
End Function
Step 4. SwitchBoard Form

Add this line in Form_load module
oMenu.InitializeMenu