MS Access VBA Interview Questions and Answers with Examples

MS Access VBA Interview Questions and Answers explained with Example macros. Here are the list of most frequently asked basic MS Access VBA interview questions. All the questions are answered with simple examples. These questions will help you to answer basic questions to deal with MS Access VBA Programming/Development.

Here is the following VBA procedure to create table in the required database using VBA.

'Create table in the required database using VBA
Sub sbCreate_Table()
 
    Dim DBase As Database
    '
    'Open Databse
    Set DBase = OpenDatabase("C:UsersPNRaoDocumentsMyDatabase.accdb")
 
    ' Create a table with three fields.
    DBase.Execute "CREATE TABLE MyTable " _
        & "(EName CHAR, ENumber INT, ELocation CHAR);"
 
    DBase.Close
 
End Sub
Here is the following VBA procedure to delete table from a specific database using VBA.

'Delete table from a specific database using VBA
Sub sbDelete_Table()
 
    Dim DBase As Database
    '
    'Open Databse
    Set DBase = OpenDatabase("C:UsersPNRaoDocumentsMyDatabase.accdb")
 
    ' Create a table with three fields.
    DBase.Execute "DROP TABLE MyTable;"
 
    DBase.Close
 
End Sub
Here is the following VBA procedure to the access database table using VBA.

'Add or Insert records to the access database table using VBA
Sub sbAdd_Records_Table()
 
    Dim DBase As Database
    Dim strSQL As String
    '
    'Open Databse
    Set DBase = OpenDatabase("C:UsersPNRaoDocumentsMyDatabase.accdb")
 
    strSQL = "INSERT INTO MyTable values('John2',12345,'U.S');"
    
    ' Adding records the table
    DoCmd.RunSQL strSQL
 
    DBase.Close
 
End Sub
Here is the following VBA procedure to update records in the access database table using VBA.

'Update records in the access database table using VBA
Sub sbUpdate_Records_Table()
 
    Dim DBase As Database
    Dim strSQL As String
    '
    'Open Databse
    Set DBase = OpenDatabase("C:UsersPNRaoDocumentsMyDatabase.accdb")
 
    strSQL = "Update MyTable set ELocation='U.K' where ENumber=12345;"
    
    ' Updating records the table
    DoCmd.RunSQL strSQL
 
    DBase.Close
 
End Sub
Here is the following VBA procedure to delete records in the access database table using VBA.

'Delete records in the access database table using VBA
Sub sbDelete_Records_Table()
 
    Dim DBase As Database
    Dim strSQL As String
    '
    'Open Databse
    Set DBase = OpenDatabase("C:UsersPNRaoDocumentsMyDatabase.accdb")
 
    strSQL = "Delete from MyTable where ENumber=12345;"
    
    ' Deleting records the table
    DoCmd.RunSQL strSQL
 
    DBase.Close
 
End Sub
Here is the following VBA procedure to alter (Add Column) table in the access database using VBA.

'Alter table in the access database using VBA
Sub sbAlter_Records_Table_AddColumn()
 
    Dim DBase As Database
    Dim strSQL As String
    '
    'Open Databse
    Set DBase = OpenDatabase("C:UsersPNRaoDocumentsMyDatabase.accdb")
 
    strSQL = "ALTER table MyTable ADD COLUMN ESal Money;"
    
    ' Alter table
    DoCmd.RunSQL strSQL
 
    DBase.Close
 
End Sub
Here is the following VBA procedure to alter (Delete Column) table in the access database using VBA.

'Alter table in the access database using VBA
Sub sbAlter_Records_Table_DeleteColumn()
 
    Dim DBase As Database
    Dim strSQL As String
    '
    'Open Databse
    Set DBase = OpenDatabase("C:UsersPNRaoDocumentsMyDatabase.accdb")
 
    strSQL = "ALTER table MyTable DROP COLUMN ESal;"
    
    ' Alter table
    DoCmd.RunSQL strSQL
 
    DBase.Close
 
End Sub
Here is the following VBA procedure to alter (Delete Column) table in the access database using VBA.

'Alter table in the access database using VBA
Sub sbAlter()
 
    Dim DBase As Database
    Dim strSQL As String
    '
    'Open Databse
    Set DBase = OpenDatabase("C:UsersPNRaoDocumentsMyDatabase.accdb")
 
    strSQL = "ALTER table MyTable DROP COLUMN ESal;"
    
    ' Alter table
    DoCmd.RunSQL strSQL
 
    DBase.Close
 
End Sub
Here is the following VBA procedure to export access table to Excel using VBA.

'Export access table to Excel using VBA?
Sub sbExport_Table_Excel()
    
    'Variable declaration
    Dim strTable As String
    Dim strWorkbook As String
    
    'Change target file path
    strWorkbook = "D:/MyTable.xlsx"
    
    'Source table name
    strTable = "MyTable"
    
    'Export table to Excel
    DoCmd.TransferSpreadsheet transfertype:=acExport, spreadsheettype:=acSpreadsheetTypeExcel12, _
    tablename:=strTable, FileName:=strWorkbook, hasfieldnames:=True
       
End Sub
Here is the following VBA procedure to change existing table name in access using VBA.

'Change existing table name in access using VBA
Sub sbChange_Table_Name()
    
    'Variable declaration
    Dim strOTable As String
    Dim strNTable As String
          
    'Old Table name
    strOTable = "MyTable"
    
    'New Table Name
    strNTable = "EmpTable"
    
    'Export table to Excel
    DoCmd.Rename strNTable, acTable, strOTable
          
End Sub
Here is the following VBA procedure to find specified data in an access table using VBA.

'Find specified data in an access table using VBA
Sub sbFindData_InTable()
    
    'Variable declaration
    Dim strData As String
          
    'Specify Data to search
    strData = "John"
    
    'find specified data
    DoCmd.FindRecord strData, , True, , True
          
End Sub
Here is the following VBA procedure to open an existing access table in Print View using VBA.

'Open an existing access table in Print View using VBA.
Sub sbPrintView_Table()
    
    'Variable declaration
    Dim strTable As String
          
    'Specify table Name
    strTable = "EmpTable"
    
    'find specified data
    DoCmd.OpenTable strTable, acViewPreview
          
End Sub
Here is the following VBA procedure to open an existing access table in design View using VBA.

'Open an existing access table in design View using VBA.
Sub sbDesignView_Table()
    
    'Variable declaration
    Dim strTable As String
          
    'Specify table Name
     strTable = "EmpTable"
    
    'find specified data
    DoCmd.OpenTable strTable, acViewDesign
          
End Sub
Here is the following VBA procedure to open an existing access table in normal View using VBA.

'Open an existing access table in normal View using VBA.
Sub sbNormalView_Table()
    
    'Variable declaration
    Dim strTable As String
          
    'Specify table Name
     strTable = "EmpTable"
    
    'find specified data
    DoCmd.OpenTable strTable, acViewNormal
          
End Sub

Here is the link for more VBA Interview Questions and Answers. These are explained for examples.
100+ VBA Interview Questions