Fungsi Format Ms Access berguna untuk memformat tampilan data. Misalnya data tanggal dapat ditampilkan dengan format sebagai berikut 15/07/2010 atau 16 Jul 2010 atau 15-07-01 sesuai dengan keinginan kita.
Cara penulisan fungsi Format adalah:
Format(expression[, format[, firstdayofweek[, firstweekofyear]]])
Bagian | Keterangan |
---|---|
expression | Harus diisi. Dapat berisi variabel atau ekpresi |
format | Opsional. Nama format yang valid * |
firstdayofweek | Opsional. Konstata hari pertama dalam seminggu |
firstweekofyear | Opsional. Konstanta minggu perama dari tahun |
Daftar Nama Format yang valid
Nama | Contoh Format |
---|---|
General Date | 6/19/2009 5:35:21 PM |
Long Date | Sunday, June 18, 1994 |
Medium Date | 19-Jun-94 |
Short Date | 6/19/1994 |
Long Time | 5:35:21 PM |
Medium Time | 5:35: PM |
Short Time | 17:35 |
General Number | 3456.789 |
Currency | $3,456.79 |
Fixed | 3456.78 |
Standard | 3,456.789 |
Percent | 123.00% |
Scientific | 3.46E+03 |
True/False | True |
Yes/No | No |
On/Off | On |
Contoh penggunaan format untuk data tanggal
Private Sub Command4_Click()
Dim strDate As Date
Dim strMsg As String
strDate = Now
strMsg = "Format Tanggal dan waktu saat ini : " & vbCrLf
strMsg = strMsg & "Short Date :" & Format(strDate, "Short Date")
strMsg = strMsg & vbCrLf
strMsg = strMsg & "Long Date :" & Format(strDate, "Long Date")
strMsg = strMsg & vbCrLf
strMsg = strMsg & "Long Date :" & Format(strDate, "Long Date")
strMsg = strMsg & vbCrLf
strMsg = strMsg & "Long Time :" & Format(strDate, "Long Time")
strMsg = strMsg & vbCrLf
strMsg = strMsg & "Short Time :" & Format(strDate, "Short Time")
strMsg = strMsg & vbCrLf
strMsg = strMsg & "User-Define :" & Format(strDate, "dd-mmm-yyyy")
MsgBox strMsg
End Sub
Hasil output:
Contoh penggunaan format untuk data angka
Private Sub Command5_Click()
Dim strAngka
Dim strMsg As String
strAngka = 12345.789
strMsg = "Format Angka : " & vbCrLf
strMsg = strMsg & "General Number: " & Format(strAngka, "General Number")
strMsg = strMsg & vbCrLf
strMsg = strMsg & "Standard: " & Format(strAngka, "Standard")
strMsg = strMsg & vbCrLf
strMsg = strMsg & "Fixed: " & Format(strAngka, "Fixed")
strMsg = strMsg & vbCrLf
strMsg = strMsg & "Scientific: " & Format(strAngka, "Scientific")
strMsg = strMsg & vbCrLf
strMsg = strMsg & "Currency: " & Format(strAngka, "Currency")
strMsg = strMsg & vbCrLf
strMsg = strMsg & "User-Define :" & Format(strAngka, "#,##0.0")
MsgBox strMsg
End SubHasil output:
No comments:
Post a Comment