vba

display list of table from other database with DAO

this function will display list of table from other database, it come handy if you want to make a tool for inventory of all your db

Sub displayTable()
Dim dbs As Database
Dim otable As DAO.TableDef
Dim ItemName As String
Set dbs = OpenDatabase(“Db Name”)
For Each otable In dbs.TableDefs
If UCase(Left(otable.Name, 3)) <> “MSY” Then
ItemName = otable.Name
ItemName = Replace(ItemName, “,”, “–”)
debug.print ItemName
ItemName = “”
End If
Next otable
Set otable = Nothing
Set dbs = Nothing
End Sub

Access link table from different database with vba

Problem:
you have lots of database with link table in it, and in one time some of path are changed.. rather than change them manually,  i create function that can do that for me :)

Solution:
In this function you can specify the link you want to find and replace it with your new link. it save me lots of time..

Function RelinkTable(setDB As String, FINDtext As String, REPLACEtext As String)
Dim dbs As Database
Dim Tdf As TableDef
Dim Tdfs As TableDefs
Set dbs = OpenDatabase(setDB)
Set Tdfs = dbs.TableDefs
‘Loop through the tables collection
For Each Tdf In Tdfs
If Tdf.SourceTableName <> “” And Tdf.Connect = “;DATABASE=” & FINDtext Then   ‘if its the linktable
Tdf.Connect = “;DATABASE=” & REPLACEtext ‘Set the new source
Tdf.RefreshLink ‘Refresh the link
End If
Next ‘Goto next table
Set dbs = Nothing
Set Tdfs = Nothing
End Function

comment block in vba msaccess

Enable the edit toolbar, hignlight lines to comment, and click the “comment block” icon on the edit toolbar (middle of toolbar). This will add the ‘ to whatever you highlight.

List of SendKeys

Key Code
BACKSPACE {BACKSPACE}, {BS}, or {BKSP}
BREAK {BREAK}
CAPS LOCK {CAPSLOCK}
DEL or DELETE {DELETE} or {DEL}
DOWN ARROW {DOWN}
END {END}
ENTER {ENTER}or ~
ESC {ESC}
HELP {HELP}
HOME {HOME}
INS or INSERT {INSERT} or {INS}
LEFT ARROW {LEFT}
NUM LOCK {NUMLOCK}
PAGE DOWN {PGDN}
PAGE UP {PGUP}
PRINT SCREEN {PRTSC} (reserved for future use)
RIGHT ARROW {RIGHT}
SCROLL LOCK {SCROLLLOCK}
TAB {TAB}
UP ARROW {UP}
F1 {F1}
F2 {F2}
F3 {F3}
F4 {F4}
F5 {F5}
F6 {F6}
F7 {F7}
F8 {F8}
F9 {F9}
F10 {F10}
F11 {F11}
F12 {F12}
F13 {F13}
F14 {F14}
F15 {F15}
F16 {F16}
Keypad add {ADD}
Keypad subtract {SUBTRACT}
Keypad multiply {MULTIPLY}
Keypad divide {DIVIDE}
Key Code
SHIFT +
CTRL ^
ALT %

Check if table is exist vba

Problem:
Check if table is exist

Solution:
Option Compare Database
Public Function TableExists(strTable As String) As Boolean
Dim strName As String

On Error Resume Next
‘If table exists already then strName will be > “”
strName = CurrentDb.TableDefs(strTable).name
TableExists = Not (strName = “”)
End Function

Get Adobe Flash playerPlugin by wpburn.com wordpress themes