This page gives hints and tips for Microsoft Access" as well giving some VB code samples.

The forms and code samples linked to by this page remain the copyrighted material of Abbydale Systems. You are free to use the material but please honor the copyrights. The usual disclaimers apply.

 
 
  Ensure Only Numbers Are Entered  
  ' This validates that numerics were entered

If KeyCode = 13 Then     ' Enter Pressed
   Exit Sub
End If

If KeyCode = 8 Then Exit Sub    ' Ignore Backspace
If KeyCode = 9 Then Exit Sub    ' Ignore Tab
If KeyCode = 44 Then Exit Sub   ' Ignore Screen Print
If KeyCode = 46 Then Exit Sub   ' Ignore delete
If KeyCode = 37 Then Exit Sub   ' Ignore backward arrow
If KeyCode = 39 Then Exit Sub   ' Ignore forward arrow
If KeyCode = 17 Then Exit Sub   ' Ignore paste
If KeyCode < 106 And KeyCode > 95 Then Exit Sub ' Allow Num-Lock Numbers

If KeyCode > 57 Or KeyCode < 48 Then
   MsgBox "Must be numeric", vbCritical, "Invalid Entry"
End If
This code will ensure that the data being entered into a field on a form is numeric.

It should be entered into your fields "KeyUp" event.

When enter is pressed (KeyCode=13) you could validate the number that was entered for length or value.

Link to NumbersOnly code

 
 
 
  Flashing Text  
  ' Make MyText Flash

If Me.MyText.Visible = True Then
   Me.MyText.Visible = False
Else
   Me.MyText.Visible = True
End If
This code will 'flash' a form control or text.

The code should be entered in the form "On Timer" event and the MyText changed to represent the control or text that you want to be flashing.

You must also set a form "Timer Interval" which, it is worth remembering, is defined in milliseconds so 30 seconds is defined as 30000.

Link to FlashText code

 
 
 
  Checking to See if a Table Exists  
  Public Function TableExtant(strTableName As String) As Boolean
Dim db As DAO.Database
Dim tbldef As DAO.TableDef
TableExtant = False
Set db = CurrentDb
For Each tbldef In db.TableDefs
   If tbldef.Name = strTableName Then
      TableExtant = True
   End If
Next tbldef
End Function


Usage :

If Not TableExtant("tblCounters") Then
   ' do something if it not existing
End If
The TableExtant function will check to see if a Table is defined in a database.

If the table exists the function will return True if it doesn't exist it will return False.

Link to TableExtant code

 
 
 
  Linking an External Table  
  DoCmd.TransferDatabase TransferType:=acLink, _
   DatabaseType:="Microsoft Access", _
   DatabaseName:="\\UNCname\YourBackendDatabase.accdb", _
   ObjectType:=acTable, _
   Source:="YourSourceTableName", _
   Destination:="YourDestinationTableName"
This code will link a table to a database. The destination name is the name that it will be used by in this database. This is the name that will appear in the Objects panel.

The source name is the name of the table in the source database to be linked to.

The Database name can be a mapped drive or the UNC (full path) name.

It is important to remember that this statement will define a linked table regardless of if it currently exists.

If a linked table of the same name is already defined a new link is defined with an appended number.

To avoid redundant tables being linked we recommend using the TableExtant function to see if the table needs defining or not.

 
 
 


If you need any support or assistance with any of the code on this site
or
if you would like to contact us, please click here

follow us on facebook
Follow us on Facebook

 

Number of unique visitors 299

Copyright © Abbydale Systems LLC 2015-2024

Abbydale Systems LLC Lic. 802696149. All rights reserved.

Last modified : Sunday 19th of September 2021