SETHA SITE INFORMATION

  • Increase font size
  • Default font size
  • Decrease font size
SETHA SITE INFORMATION

Getting Start with Microsoft Visual Basic 2008

E-mail Print PDF

If you already know how to program in Visual Basic 6 then you will be able to move quickly into Visual Basic 2008. The below video show you:
- How to create project in Microsoft Visual Basic 2008?
- How to create new form in Microsoft Visual Basic 2008?
- Where is the project folder?


Download Video Here

 

How to Save Image into Table in Microsoft Access Using VB 2008

E-mail Print PDF

Please follow the instruction below:

  • Step 1: Create Database in Microsoft Access
    • Database: data.mdb
    • Create Table: tblstudent(stdid: Number, name: text, photo: OLE Object)
  • Step 2: Create Visual Basic 2008 Project
    • Create and Save Project in Visual Basic 2008
    • Put the database file (data.mdb) in the project execution folder (\bin\debug\)
    • Create Form named: frmStudent (view as the following image)

  • Step 3: Write Code in Visual Basic 2008
    On Click [Button Add]
    Dim cn As New OleDb.OleDbConnection
    cn.ConnectionString = "Provider=Microsoft.Jet.OleDb.4.0; Data Source=" & _
                          Application.StartupPath & "\data.mdb"
    cn.Open()
    
    Dim arrImage() As Byte
    Dim strImage As String
    Dim myMs As New IO.MemoryStream
            '
    If Not IsNothing(Me.picPhoto.Image) Then
         Me.picPhoto.Image.Save(myMs, Me.picPhoto.Image.RawFormat)
         arrImage = myMs.GetBuffer
         strImage = "?"
    Else
         arrImage = Nothing
         strImage = "NULL"
    End If
    
    Dim myCmd As New OleDb.OleDbCommand
    myCmd .Connection = cn
    myCmd .CommandText = "INSERT INTO tblstudent(stdid, [name], photo) " & _
                      " VALUES(" & Me.txtID.Text & ",'" & _
                      Me.txtName.Text & "'," & strImage & ")"
    If strImage = "?" Then
          myCmd.Parameters.Add(strImage, OleDb.OleDbType.Binary).Value = arrImage
    End If
    
    MsgBox("Data save successfully!")
    myCmd .ExecuteNonQuery()
    cn.Close()
    


    On Click [Button Search]
    Dim cn As New OleDb.OleDbConnection
    cn.ConnectionString = "Provider=Microsoft.Jet.OleDb.4.0; " & _
                         " Data Source=" & Application.StartupPath & "\data.mdb"
    cn.Open()
    
    Dim arrImage() As Byte
    Dim myMS As New IO.MemoryStream
    Dim da As New OleDb.OleDbDataAdapter("SELECT * FROM tblstudent " & _
                                         " WHERE stdid=" & Me.txtID.Text, cn)
    Dim dt As New DataTable
    da.Fill(dt)
    
    If dt.Rows.Count > 0 Then
         Me.txtName.Text = dt.Rows(0).Item("name") & ""
         If Not IsDBNull(dt.Rows(0).Item("photo")) Then
                arrImage = dt.Rows(0).Item("photo")
                For Each ar As Byte In arrImage
                        myMS.WriteByte(ar)
                Next
                    '
                Me.picPhoto.Image = System.Drawing.Image.FromStream(myMS)
          End If
          Me.btnAdd.Enabled = False
    Else
          MsgBox("Record not found!")
    End If
    
    cn.Close()
    


Download Sample Code Here

 

How to Connect from VB 2008 to Microsoft Access 2003

E-mail Print PDF

This sample code is programmed in Visual Basic 2008 shows you how to connect to Microsoft Access 2003 (*.mdb) from Visual Basic 2008. In this sample, database file (data.mdb) is located in the project folder (..\bin\debug\data.mdb).

Dim Cnn As New OleDb.OleDbConnection()
Cnn.ConnectionString = "Provider=Microsoft.Jet.OleDb.4.0; " & _
                       "Data Source=" & Application.StartupPath & "\data.mdb;" & _
                       "Persist Security Info=False;"
Cnn.Open()

MsgBox("Connection established!")
 

How to Connect from VB 2008 to Microsoft Access 2007

E-mail Print PDF

This sample code is programmed in Visual Basic 2008 shows you how to connect to Microsoft Access 2007 (*.accdb) from Visual Basic 2008. Database file (data.accdb) is placed in the project folder (..\bin\debug\data.accdb).

Dim Cnn As New OleDb.OleDbConnection()
Cnn.ConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0; " & _
                       "Data Source=" & Application.StartupPath & "\data.accdb;" & _
                       "Persist Security Info=False;"
Cnn.Open()

MsgBox("Connection established!")
Download Sample Code Here
 

* Note: If you have problem with Access Database Engine from running the above code please download the below link:
1. For Microsoft Access 2007 Click Here
2. For Microsoft Access 2010 Click Here

 

How to Create Customized Ribbon in Microsoft Access 2007

E-mail Print PDF

This article shows you one scenario about how to create a customized Office Fluent Ribbon in Microsoft Access 2007. This article applies to only Microsoft Office Access Database not include the Microsoft Office Access Project (*.ADP). To customized our own Ribbon we need to know some of XML markup text.

Scenario for creating customized Office Fluent Ribbon in Microsoft Access 2007

  • Step 1: Create New Project Database or Open your existing Project Database
  • Step 2: Create New Table named USysRibbons with the following fields:
    Field NameData TypeDescription
    RibbonNameTextUnique name that identifies the UI extensibility customizations in the RibbonXML field.
    RibbonXMLMemoRibbonXML that describes a set of customizations to be applied to the Office Fluent UI.
  • Step 3: Create one Tab named Home
    Add New record to USysRibbons table as below:
    Field NameContent
    RibbonNameHome
    RibbonXML
    <customUI 
     xmlns="http://schemas.microsoft.com/office/2006/01/customui">
     <ribbon startFromScratch="true">
      <tabs>
       <tab id="tabMain" label="Home">
       </tab>
      </tabs>
     </ribbon>
    </customUI>
    

    * Note: Use <tab id="..." label="..."></tab> tag to create Tab on Ribbon.
  • Step 4: Set your customized Ribbon as the Startup Ribbon
    • Close and restart the application.
    • Click the Microsoft Office Button, and then click Access Options.
    • Click Current Database in the left pane.
    • In the Ribbon and Toolbar Options section, select the Home Ribbon in the Ribbon Name list.
    • Close and restart the application.


     
  • Step 5: Create Group named List
    Modify the above record in USysRibbons table as below:
    Field NameContent
    RibbonNameHome
    RibbonXML
    <customUI 
     xmlns="http://schemas.microsoft.com/office/2006/01/customui">
     <ribbon startFromScratch="true">
      <tabs>
       <tab id="tabMain" label="Home">
          <group id="grpList" label="List">
          </group>
       </tab>
      </tabs>
     </ribbon>
    </customUI>
    

    * Note: Use <group id="..." label="..."></group> tag to create Group under the Tab of Ribbon.

     
  • Step 6: Create Button in List Group
    Just modify the record in USysRibbons table as follow
    Field NameContent
    RibbonNameHome
    RibbonXML
    <customUI 
     xmlns="http://schemas.microsoft.com/office/2006/01/customui">
     <ribbon startFromScratch="true">
      <tabs>
       <tab id="tabMain" label="Home">
          <group id="grpList" label="List">
            <button id="cmdBook" label="Book" size="large" 
                supertip="Click here to show list of book"/>
          </group>
       </tab>
      </tabs>
     </ribbon>
    </customUI>
    

    * Note: Use <button id="..." label="..." site="..." supertip="..."></button> tag to create Button in the Group under the Tab of Ribbon.

     
  • Step 7: Add Image to Button
    Modify the above record in table USysRibbons by adding the imageMso attribute into the <button> tag as follow:
    <button id="cmdBook" label="Book" size="large" 
      imageMso="ControlLayoutStacked" 
      supertip="Click here to show list of book"/>
    


     
  • Step 8: Add Action Click on Button
    • Modify the above record in table USysRibbons by adding onAction attribute into the <button> tag as follow:
      <button id="cmdBook" label="Book" size="large" 
        onAction="macRibbons.btnBookClick" 
        imageMso="ControlLayoutStacked" 
        supertip="Click here to show list of book"/>
      
    • Create a macro object named macRibbons
      • Add one macro named cmdBookClick in macRibbons object
      • Choose Action: RunCode
      • In Function Name at the bottom write: btnBookClick()
    • Create function named btnBookClick() in VBA code in a module as follow:
      Public Function btnBookClick()
          MsgBox "Testing click on Book Button"
      End Function
      
    • Close and restart your application

Ref:http://msdn.microsoft.com/en-us/library/bb187398(v=office.12).aspx
 


Page 15 of 19