Link to home
Start Free TrialLog in
Avatar of spaced45
spaced45Flag for United States of America

asked on

Access Frontend Database Creating "Local" Tables Using Visual Basic

I posted a question yesterday requesting assistance on optimizing split database for Access due to network performance. Here is the link to my initial question I got good advice which led me to post this question.

I looking to have my front end DB create "local" tables based on linked tables to improve performance. I was thinking that I would only do this for reference tables and leave the transactional tables still as linked tables. All my tables on the backend have a last mod timestamp in them. I was thinking to create a table containing the table name and max mod timestamp. This table would then link to the frontend so on open it would be able to check if the local tables need to be updated.  I have a form on the frontend that opens on db open that the user logs in with. I was hoping to attach some VB to that form that would run the check on the last mod table table and then execute code to update the tables as needed.

Is this possible? Has anyone done anything similar? Any assistance with this would be very much appreciated as my deadline to get this done is fast approaching

Thank you
Avatar of Boyd (HiTechCoach) Trimmell, Microsoft Access MVP 2010-2015
Boyd (HiTechCoach) Trimmell, Microsoft Access MVP 2010-2015
Flag of United States of America image

I use a local back end for this all created with VBA code/

Also see: Lookup Table Manager
This utility started because of a project I was working on, that had several large lookup tables, that were semi-static, that means that they are not changed very often, but they can actually be updated when the user wish to add something. Until this I was using almost always linked tables, but this time the lookup tables were really large and the network as a bit slow. So I started thinking in a way to make this lookup tables local, this would increase performance and reduce network traffic.
Here is code to build a table on the fly:
Public Function ExportCensusData(FacCode As String)

Dim SQL As String
Dim DB As DAO.Database
Dim RS As DAO.Recordset

Dim TableName As DAO.TableDef
Dim FieldName As DAO.Field
Dim FieldProperty As DAO.Property

Dim Qry As DAO.QueryDef


Dim I As Integer
Dim ResID As Integer
Dim ActionCd As String

'Dim FacCode As String

'FacCode = "Census"



If DoesTblExist("LocCensusTbl") = True Then
    DoCmd.SetWarnings False
    DoCmd.DeleteObject acTable, "LocCensusTbl"
    DoCmd.SetWarnings True
End If

Set DB = CurrentDb()
Set TableName = DB.CreateTableDef("LocCensusTbl")
    
    With TableName
        .Fields.Append .CreateField("Facility_Code", dbText, 5)
        .Fields.Append .CreateField("Client_Id_Number", dbText, 35)
        .Fields.Append .CreateField("Effective_Date", dbDate)
        .Fields.Append .CreateField("Status_code", dbText, 5)
        .Fields.Append .CreateField("Action_code", dbText, 5)
        .Fields.Append .CreateField("Adt_tofrom", dbInteger)
        .Fields.Append .CreateField("Primary_payer_code", dbText, 20)
        .Fields.Append .CreateField("Rugs_code", dbText, 5)
        .Fields.Append .CreateField("Rugs_modifier_code", dbText, 2)
        .Fields.Append .CreateField("Adt_tofrom_loc", dbText, 100)
        .Fields.Append .CreateField("Assess_ref_date", dbDate)
        .Fields.Append .CreateField("Outpatient_status", dbText, 1)
        .Fields.Append .CreateField("Admission_type_code", dbInteger)
        .Fields.Append .CreateField("Admission_source_code", dbInteger)
        .Fields.Append .CreateField("UnitDescription", dbText, 35)
        .Fields.Append .CreateField("FloorDescription", dbText, 50)
        .Fields.Append .CreateField("RoomDescription", dbText, 60)
        .Fields.Append .CreateField("BedDescription", dbText, 30)
        .Fields.Append .CreateField("HospitalStayFrom", dbDate)
        .Fields.Append .CreateField("HospitalStayTo", dbDate)
        .Fields.Append .CreateField("RESIDENT_ID", dbLong)
        .Fields.Append .CreateField("RES_STAY_ID", dbLong)
        .Fields.Append .CreateField("SeqNum", dbInteger)
        .Fields.Append .CreateField("IdNum", dbLong)
    End With
    
    With TableName
        .Fields("Facility_Code").DefaultValue = FacCode
        .Fields("IdNum").Attributes = dbAutoIncrField
        .Fields("UnitDescription").AllowZeroLength = True
        .Fields("FloorDescription").AllowZeroLength = True
        .Fields("RoomDescription").AllowZeroLength = True
        .Fields("BedDescription").AllowZeroLength = True
    End With

DB.TableDefs.Append TableName

Set FieldName = TableName.Fields("Effective_date")
Set FieldProperty = FieldName.CreateProperty("Format", dbText, "mm/dd/yyyy")
FieldName.Properties.Append FieldProperty

Set FieldName = TableName.Fields("Assess_ref_date")
Set FieldProperty = FieldName.CreateProperty("Format", dbText, "mm/dd/yyyy")
FieldName.Properties.Append FieldProperty

End Function

Open in new window


The DoesTblExist function:
Public Function DoesTblExist(strTblName As String) As Boolean
    On Error Resume Next
    Dim DB As DAO.Database
    Dim Tbl As DAO.TableDef
    Set DB = CurrentDb
    Set Tbl = DB.TableDefs(strTblName)
    If Err.Number = 3265 Then   ' Item not found.
       DoesTblExist = False
       Exit Function
    End If
    DoesTblExist = True
End Function

Open in new window

I forgot to post this link:

The TempTables.MDB illustrates how to use a temporary MDB in your Microsoft Access app.

I use a local back end for this so it can easily be compacted. I can also update the front end without having to refresh the local cached look up tables.
Avatar of spaced45

ASKER

I think that this will certainly be able to do the trick though from what I am seeing in the code this would be executed once if the table doesn't exist. Right? What if I make a change to the table and need it to execute this again so that the local table/s are updated?

Before I was able to read the posts I took it a step further and pre-created the tables with no data. I was then that when the database opened it could, first check if the local table contained data and second if data was present then check for updates.

Would this still be possible?
HiTech,

tried to take a look at how the Look Manager example worked but I got some errors dealing with conversions and user-level permissions that are no longer supported in later versions of access.
spaced45,

Did you rad the article text about the Lookup Table Manager. It has some incites into what you will need need to address. to make this work.

For me, since 100 Mb NICs and Citrix/Terminal Server were available I have not had to deal with any network performance issues. Even with WAN/VPN and wireless connections.  The only performance issues I deal with now are programming/database design issues.

I did a cursory scan of your precious post. Is part of your network peformance issues related to using a WAN via a VPN?   In these situations I use a Terminal Server.  This solves performance issues with a WAN/VPN and wifi networks.. I have some sites with 30+ concurrent  users using Terminal Services from multiple cities across the US with no performance issues or database corruption.
ASKER CERTIFIED SOLUTION
Avatar of Jim P.
Jim P.
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Looks like it working perfectly. thank you for all the assistance