Centralize data into a single data storage have become a critical task for any software application. This single storage point can be used as an input for other applications as well.


In this article, I will be demonstrating how to export Mi-Form Form Data to MS-Access. Assuming we have a MS-Access database as below.





Your Mi-Form Form should have the same fields that will be mapped to the columns.

   

Function ExportToODBC(ByRef strMessage As String) As Boolean
        Dim myConnection As System.Data.Odbc.OdbcConnection

        Try
            myConnection = New System.Data.Odbc.OdbcConnection("Driver={Microsoft Access Driver (*.mdb)};DBQ=" & "C:\MobilitySummit\msaccess\Customers.mdb")
            If (myConnection Is Nothing) Then               
                Return False
            End If
            myConnection.Open()
        Catch ex As System.Exception
            strMessage = ex.Message
            Return False
        End Try

        Try
            Dim strSQL As String = _
             String.Format("insert into Customers(Name,Address1,City,State,ZIP,Phone,Ext,Email,BillName,BillAddress1,BillCity,BillState,BillZIP,BillPhone,BillExt,BillEmail) "  + _
						"values('{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}','{8}','{9}','{10}','{11}','{12}','{13}','{14}','{15}')",_CustName.Value,_CustAddress.Value,_CustCity.Value,_CustState.Value,_CustZIP.Value,_CustPhone.Value,_CustPhoneExt.Value,_CustEmail.Value _
						,_BillName.Value,_BillAddress.Value,_BillCity.Value,_BillState.Value,_BillZIP.Value,_BillPhone.Value,_BillPhoneExt.Value,_BillEmail.Value)
            
			LogMessage("SQL: " & strSQL)

            Dim myCmd As New System.Data.Odbc.OdbcCommand(strSQL, myConnection)
            Dim nRows As Integer = myCmd.ExecuteNonQuery()
            strMessage = "Success"
            Return True
        Catch ex As System.Exception
            strMessage = ex.Message
            Return False
        Finally
            myConnection.Close()
        End Try

    End Function

 

 It depends on where you want to export the database. It can be on client side or server. Assuming you want to export the MS-Access database on server side. You can handle Form_AfterDataPathsRun event and call the export function.

 

 <MiCode(FormScriptEventType.AfterDataPathsRun)> _ 
    Public Sub Form_AfterDataPathsRun(ByVal e As AfterDataPathsRunEventArgs)
        ExportToODBC("") 
    End Sub