ADO 100% Tanpa Membuat Database

masukkan adodc, listbox, command1, command2, command3, text1, text2, text3
langsung aja deh, neh source code-nya
copy paste aja biar cepet ga ngerepotin plus kebiasaan😛

Option Explicit

Dim StrRec As ADODB.Recordset
Dim StrNav As ADODB.Recordset
Dim NamaFile As String
Sub BukaText()
Set StrRec = New ADODB.Recordset
With StrRec
.CursorLocation = adUseClient
.LockType = adLockBatchOptimistic
.Filter = “”
End With
End Sub

Sub TutupText()
Set StrRec = Nothing
End Sub

Function getLokasi() As String
Dim buff As String
If Right(App.Path, 1) = “\” Then
buff = App.Path
Else
buff = App.Path & “\”
End If
getLokasi = buff
End Function

Sub LoadTextFile()
‘List1.Clear
BukaText
With StrRec
.Open NamaFile
While Not .EOF
‘ List1.AddItem !NRP
‘ .MoveNext
Wend
End With
TutupText
End Sub

Sub DefaultBuatFileText()
NamaFile = getLokasi & “Siswa.txt”
If Dir(NamaFile) = “” Then
Call BuatHeader
End If
End Sub

Public Sub BuatHeader()
Set StrRec = New ADODB.Recordset
With StrRec
Set .ActiveConnection = Nothing
.CursorLocation = adUseClient
.LockType = adLockBatchOptimistic
.CursorType = adOpenDynamic
With .Fields
.Append “NRP”, adVarChar, 7, adFldKeyColumn
.Append “Nama”, adVarChar, 50
.Append “Alamat”, adVarChar, 50
End With
.Open
.Save NamaFile, adPersistADTG
TutupText
End With
End Sub

Private Sub Command1_Click()
Dim i
For i = 1 To 500
BukaText
Text1 = i
With StrRec
.Open NamaFile
.AddNew
.Fields(“NRP”) = Trim(Text1.Text)
.Fields(“Nama”) = Trim(Text2.Text)
.Fields(“Alamat”) = Trim(Text3.Text)
.Save NamaFile, adPersistADTG
LoadNavigator
StrNav.MoveLast
End With
TutupText
Next i
End Sub

Private Sub Command2_Click()
BukaText
With StrRec
.Open NamaFile
.Filter = “”
.Find “NRP='” & Text1.Text & “‘”
If .EOF = False Then
If MsgBox(“Mo Delete neh…….”, 64 + vbYesNo) = vbYes Then
.Delete adAffectCurrent
LoadNavigator
Command3_Click 3
.Save NamaFile, adPersistADTG

End If
Else
MsgBox “Data tidak ditemukan.”
End If
End With
TutupText

End Sub

Private Sub Command3_Click(Index As Integer)

With StrNav
If .EOF Then
TutupText
Exit Sub
End If
Select Case Index
Case 0
.MoveFirst
Case 1
.MovePrevious
If .BOF Then .MoveFirst
Case 2
.MoveNext
If .EOF Then .MoveLast
Case 3
.MoveLast
End Select
Text1 = !NRP
Text2 = !nama
Text3 = !alamat
End With
End Sub
Sub LoadNavigator()
Set StrNav = New ADODB.Recordset
StrNav.Open NamaFile
End Sub
Private Sub Form_Load()
On Error GoTo cv
DefaultBuatFileText
LoadNavigator
Command3_Click 0
Exit Sub
cv:
If Dir(getLokasi & “Siswa.txt”) <> “” Then Kill getLokasi & “Siswa.txt”
DefaultBuatFileText
End Sub

http://www.vb-bego.com

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s


%d bloggers like this: