Wednesday, 4 January 2012

MS-Access: Chain of events while deleting a record on a form

When you delete a record, the following events occur for the form:

    1 - Form's Delete event occurs before its BeforeDelConfirm event. Both can be cancelled if desired.
 
    2 - At Delete event stage, the record under deletion is still the current one and correct values for various controls are returned. By the time you encounter BeforeDelConfirm event, the record next to that meant for deletion becomes the current record and the values returned can be misleading.
 
    3 - If Delete event is cancelled, subsequent events (i.e. BeforeDelConfirm and AfterDelConfirm) don't fire.
 
    4 - AfterDelConfirm event is the last one to fire, provided delete event itself has not been cancelled. It returns Status values as follows:
    (a) 0 for actual implementation of deletion
    (b) 1 for programmatic cancellation at BeforeDelConfirm stage
    (c) 2 for cancellation by user in response to prompt at BeforeDelConfirm stage
 
The following example shows how you can use the BeforeDelConfirm event procedure to suppress the Delete Confirm dialog box and display a custom dialog box when a record is deleted. It also shows how you can use the AfterDelConfirm event procedure to display a message indicating whether the deletion progressed in the usual way or whether it was canceled in Visual Basic or by the user.
 
Private Sub Form_BeforeDelConfirm(Cancel As Integer, _
        Response As Integer)
    ' Suppress default Delete Confirm dialog box.
    Response = acDataErrContinue
    ' Display custom dialog box.
    If MsgBox("Delete this record?", vbOKCancel) = vbCancel Then
        Cancel = True
    End If
End Sub

Private Sub Form_AfterDelConfirm(Status As Integer)      
    Select Case Status
        Case acDeleteOK  
            MsgBox "Deletion occurred normally."  
        Case acDeleteCancel  
            MsgBox "Programmer canceled the deletion."  
        Case acDeleteUserCancel  
            MsgBox "User canceled the deletion."     
    End Select 
End Sub

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: