by MYLE
17. March 2011 06:54
- Make sure you start with a properly-normalized database design and that you understand all of the fields and relationships before beginning to code.
- Don't allow users to see or edit tables directly, but only through forms. Don't use "Lookup Fields" (at least, not on a table level) either, as they can lead to confusion.
- Choose a naming convention and use it. Never allow spaces in names.
- Write comments in your procedures and explain each variable. Do this as you code: don't rely on going back "once the program's done".
- Understand error handling and use it faithfully in all procedures.
- Split your databases into a front-end and back-end.
- Don't use Autonumber if the field is meant to have meaning for the users.
- Don't copy and paste other people's code without at least attempting to understand what it does.
- Don't use "SendKeys", "Smart Codes" or "GoTo" (unless the GoTo is part of an OnError process)
- Back-up the database faithfully. Never make changes on the Production Database, but on the Prototype Copy instead.
d2ebde4c-29a6-4cbb-a53f-a96ffccb3ad4|0|.0
by MYLE
16. July 2010 00:09
Here some code I found that will let you change the status bar in MSaccess
Function StatusBar(Message)
Dim RetVal As Variant
RetVal = SysCmd(4, Message)
End Function
Call StatusBar("Hello There")
Microsoft SysCmd
6481a87d-0c9d-489d-95d5-94ed136c4eaf|0|.0
by MYLE
16. July 2010 00:01
Every wanted to be able let the User Change the printer in MSaccess
Dim prt As Printer
For Each prt In Application.Printers
Me!Myprinter.AddItem Item:=prt.DeviceName
Next prt
where Me!Myprinter is a combo box on the form Now Printing that report
Dim prt
Set prt = Application.Printers(Me!Myprinter)
Set Application.Printer = prt
stDocName = "That Report"
DoCmd.OpenReport stDocName, acNormal
Set Application.Printer = Nothing
f5f6eb9d-9184-4207-a8f9-c0da0c06c515|0|.0
Category: MSaccess
Tags: Printing
by MYLE
21. June 2010 21:49
I have been ask many time what the best way to store hours in a data base.
as hour is a mod 60 what I do store MINS and use the below function to convert the mins to time format so
if a job took me 1:30 I store the min value 90min then if a did and other hour store that as 60 then add the mins up 150min total pass the
total = Mintohrs(150)
total would show 02:30 HrstoMin
Function Mintohrs(Tmin)
hh = Int(Tmin / 60)
tt = hh * 60
mm = Tmin - tt
Mintohrs = DIG(hh) & ":" & DIG(mm)
End Function
hourtomin
my other Functions
03:15 = Mintohrs(90+90+15)
I use and other Function I wrote to format the Mins
c9b9ba64-9cbd-4b74-b92f-75d3c1dd04e6|1|5.0
Category: ASP, MSaccess, VB
Tags:
by MYLE
21. June 2010 21:44
Here
Function DIG(num)
if len(num)<>2 then
DIG ="0" & num
else
DIG = num
end if
End Function
c708b2aa-be88-4b33-8653-5a907fe924bc|0|.0
Category: VB, MSaccess
Tags:
by MYLE
21. June 2010 21:39
some ask me need to know the age of someone to the Month ie 45.5 months don't know why but ....
Function Age(Birth_Date,End_Date)
'***************************************
' Works out the age of to the month
'
'***************************************
Dim Months
Dim Years
Dim Temp
If IsNull(Birth_Date) or Birth_Date ="" Then
Age=0.0
else
Months = DateDiff("m", CDate(Birth_Date), End_Date)
Years = Int(Months / 12)
Temp = Years * 12
If Years = 0 then Years = ""
Age = Years & "." & Months - Temp
End if
End Function
MyAge = age(DOB,now())
0d0a0270-b254-44e6-a4e1-43415727e692|0|.0
Category: ASP, MSaccess, VB
Tags:
by MYLE
21. June 2010 21:23
I had to Find the Last day on the Month that the hard bit but got thinking why note just find the first day on the next month then -1 day form that so here it is
Function st1month(Tdate)
st1month = DateSerial(Year(Tdate), Month(Tdate) + 1, 1)
End Function
OK now let find the Last day on month
Function LastDay(Tdate)
Lastd = dateadd("m",1,st1month(Tdate))
LastDay = DateAdd("d", -1, Lastd)
End Function
Must have both function in your code.
8959c389-2c45-470d-8961-4b0b588a1b98|0|.0
Category: MSaccess, VB, Dislexia
Tags:
by MYLE
18. June 2010 21:16
Some handy function
Function ReportFolderStatus(fldr) As Boolean
Dim fso, msg
Set fso = CreateObject("Scripting.FileSystemObject")
If (fso.FolderExists(fldr)) Then
ReportFolderStatus = True
Else
ReportFolderStatus = False
End If
Set fso = Nothing
End Function
Function CreateFolder(FolderName)
On Error Resume Next
Dim fso, f
If Not ReportFolderStatus(FolderName) Then
Set fso = CreateObject("Scripting.FileSystemObject")
Set f = fso.CreateFolder(FolderName)
End If
Set fso = Nothing
End Function
Sub SaveAction(FullPathFile, FeildName, strEntry, Deleteit)
'write the data to a log file
If Deleteit And ReportFileStatus(FullPathFile) Then Kill FullPathFile
Dim strErrMsg, f, fsoLog
Set fsoLog = CreateObject("Scripting.FileSystemObject")
Set f = fsoLog.OpenTextFile(FullPathFile, 8, True, -2)
Outline = FeildName & ":" & strEntry
f.WriteLine Outline
f.Close
Set fsoLog = Nothing
End Sub
Function ReportFileStatus(filespec)
Dim fso, msg
Set fso = CreateObject("Scripting.FileSystemObject")
If (fso.FileExists(filespec)) Then
ReportFileStatus = True
Exit Function
Else
ReportFileStatus = False
Exit Function
End If
Set fso = Nothing
End Function
05236a39-aec2-4b3d-b4fa-8b8c433f8cc2|0|.0
Category: MSaccess, VB
Tags:
by MYLE
18. June 2010 21:04
base on the dlookup function in MSaccess
Sub UpLookup(Feild, FeildValue, Table, Crit)
Dim SQL As String
Dim DB As Database
Dim rs As Recordset
Set DB = CurrentDb
SQL = ""
SQL = " SELECT " & Table & ".*"
SQL = SQL & " FROM " & Table & ""
SQL = SQL & " WHERE " & Crit
Set rs = DB.OpenRecordset(SQL)
If Not rs.EOF Then
rs.Edit
rs.Fields(Feild) = FeildValue
rs.Update
End If
rs.Close
End Sub
3cad30c3-af01-403f-86a7-df3549682d9f|0|.0
Category: VB, MSaccess
Tags:
by MYLE
10. June 2010 05:13
I first wrote this function in lotus 123
off top of heap going back 20+ year +iif((a1 mod 7)>0,a1-(a1 MOD7)+7,a1)) please don't quote me on this
this would of been one of my first function I wrote
Public Function WEEKEND(dat) As Date
If IsNull(dat) Then Exit Function
dat = DateSerial(Year(dat), Month(dat), Day(dat))
If dat Mod 7 > 0 Then
WEEKEND = dat - dat Mod 7 + 7
Else
WEEKEND = dat
End If
End Function
I know the Above Function works in VB
Work in
excel
Msaccess
e3d88167-1b0a-4179-bbba-a922e26c19ef|1|5.0