Updating data in Tables at two remote locations

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I am involved in updating two same Access 2003, databases in two locations.
The only available link is by e-mail. This is because one Database is in my
Ship at sea and other is in office at shore. There is no Internet facilty on
board ship, but there is an e-mail system which uses Telex over radio
technology. An e-mail can be sent with attachments as e-mail.

My requirement is once user press a command button in his database either at
ship or shore office form, a VBA code has to look in e-mail prgram for the
latest e-mail received with an attachment , then run the update record code
to update data. Is it possible to do this? Any ideas are greatly appreciated.

Programmer at sea
--
 
We use this third-party tool to automate the saving of attachments ...

http://www.sperrysoftware.com/Outlook/Attachment-Save.asp

Once the attachments are saved, it's a simple matter of looping through the
files in the target directory, importing each file, and renaming or moving
the file after import (so that the code will not attempt to import the same
file more than once).

Here's some code from one of my own apps ...

Public Sub ReadText()

Dim strInput As String
Dim intInput As Integer
Dim intOutput As Integer
Dim strLine As String

Dim db As DAO.Database
Dim rst As DAO.Recordset

Dim strCompanyCode As String
Dim strCompanyName As String
Dim strOutputDate As String
Dim dtmOutputDate As Date
Dim strFileNumber As String

Dim lngTransactions As Long
Dim curAmount As Currency
Dim curTotal As Currency

Dim strProcessDate As String
Dim dtmProcessDate As Date
Dim strSummaryDate As String
Dim dtmSummaryDate As Date

Dim lngReportedTransactions As Long
Dim curReportedAmount As Currency

Set db = CurrentDb
Set rst = db.OpenRecordset("SELECT * FROM tblTransaction",
dbOpenDynaset, dbAppendOnly)

strInput = Dir("C:\BillPay\Input\*.DAT")
Do Until strInput = vbNullString
intInput = FreeFile
Open "C:\BillPay\Input\" & strInput For Input As intInput
intOutput = FreeFile
Open "C:\BillPay\Done\" & strInput For Output As intOutput
Do Until EOF(intInput)
Line Input #intInput, strLine
Select Case Left$(strLine, 1)
Case "H"
'Header
strCompanyCode = Mid$(strLine, 2, 2)
strCompanyName = Trim$(Mid$(strLine, 4, 30))
'ddmmyy
strOutputDate = Mid$(strLine, 34, 6)
dtmOutputDate = DateSerial(CInt(Right$(strOutputDate, 2)),
CInt(Mid$(strOutputDate, 3, 2)), _
CInt(Left$(strOutputDate, 2)))
strFileNumber = Mid$(strLine, 40, 2)
lngTransactions = 0
curTotal = 0
Print #intOutput, strLine
Case "D"
'Detail
lngTransactions = lngTransactions + 1
With rst
.AddNew
.Fields("FileName") = strInput
.Fields("CompanyCode") = strCompanyCode
.Fields("CompanyName") = strCompanyName
.Fields("OutputDate") = dtmOutputDate
.Fields("FileNumber") = strFileNumber
.Fields("BatchNumber") = Mid$(strLine, 2, 8)
.Fields("SequenceNumber") = Mid$(strLine, 10, 8)
.Fields("TransactionCode") = Mid$(strLine, 18, 3)
.Fields("GrofNumber") = Mid$(strLine, 21, 4)
.Fields("AccountNumber") = Mid$(strLine, 25, 11)
curAmount = (CCur(Mid$(strLine, 36, 6)) / 100)
.Fields("AmountPaid") = curAmount
curTotal = curTotal + curAmount
'yymmdd
strProcessDate = Mid$(strLine, 42, 6)
dtmProcessDate = DateSerial(CInt(Left$(strProcessDate,
2)), CInt(Mid$(strProcessDate, 3, 2)), _
CInt(Right$(strProcessDate, 2)))
.Fields("ProcessDate") = dtmProcessDate
'undocumented, appears to be ddmmyy
strSummaryDate = Mid$(strLine, 48, 6)
dtmSummaryDate = DateSerial(CInt(Right$(strSummaryDate,
2)), CInt(Mid$(strSummaryDate, 3, 2)), _
CInt(Left$(strSummaryDate, 2)))
.Fields("SummaryDate") = dtmSummaryDate
.Fields("DateGrof") = Mid$(strLine, 54, 4)
.Update
End With
Print #intOutput, strLine
Case "T"
lngReportedTransactions = CLng(Mid$(strLine, 2, 7))
curReportedAmount = CCur(Mid$(strLine, 9, 10)) / 100
If lngReportedTransactions <> lngTransactions Then
MsgBox "Number of reported transactions does not match
actual number. File name: " & strInput
End If
If curReportedAmount <> curTotal Then
MsgBox "Reported amount does not match actual amount.
File name: " & strInput
End If
Print #intOutput, strLine
Case Else
MsgBox "Unrecognized record type!"
On Error Resume Next
Close
rst.Close
Exit Sub
End Select
Loop
Close intInput
Close intOutput
Name "C:\BillPay\Input\" & strInput As "C:\BillPay\Input\" &
Left$(strInput, InStrRev(strInput, ".")) & "BAK"
strInput = Dir()
Loop
rst.Close
MsgBox "Finished"

On Error Resume Next
Close
rst.Close

End Sub
 
Brendan
Thank you for great hlep. I extracted from your code and tried. This give an
error with key words such as "DAO.Database". The reason may be that in VBA
references in my databases only 1 VBA, 2 Access 11.0 Library, 3 ActiveX DO
2.1 Library and finally 4 OLE Automation are selected.

Do I have to select any other references? If I do that is it going to effect
the size of the files that need to be transfered and size of the databases in
general? I am going to use a telex over radio system in transfering e-mail
attachments from ship to shore Files larger than 2MB is seems loose the link
and hence unable to transfer.

With reference to the link you have given, I understand that it is mainly
for outlook express. On board ship Iuse a third party e-mail program supplied
by Globe Wireless and as far as I am aware, I cant configure Globe email to
run Outlook.
Best regards

Programmer At Sea
 
You will need to either add a link to the Microsoft DAO 3.6 Object Library
(my recommendation) or modify the code to use ADO instead of DAO. The code
is quite specific to the format of the data being imported, and the
structure of the table or tables to which it is being imported, so you will
need to modify it anyway, you will not be able to use it 'as is'.

This code will run in the application that imports the files, so it does not
have anything to do with the size of the files.

The utility we use is an add-in for Outlook (not Outlook Express, which
despite the name is a different application) so you are correct that you
will not be able to use it if you are not using Outlook. I'm not familiar
with the Globe e-mail application, so I'm afraid I can't help you there.
 
Back
Top