benar lebih baik field no_nota dibuat primary key.
anda bisa buat pengecekan no_nota saat lost_focus dari isian no_nota (jika
nomor nota diisi & tidak otomatis)
misal:
buat koneksi database terlebih dulu misal namanya : cn
cek nomor nota sbb:
Dim rsNota as new adodb.recordset
rsNota.ActiveConnection = cn
rsNota.open "SELECT No_Nota from TableName1 WHERE No_Nota='" &
txtNo_Nota.text & "'",,adOpenForwardOnly
If Not rsNota.EOF Then
MsgBox "Nomor Nota sudah ada!",vbOkOnly
txtNo_Nota.setFocus
exit sub
endif
rsNota.close
set rsNota=nothing
script diatas akan mengecek nomor nota, jika sudah ada dia akan menampilkan
pesan & set focus kembali ke txtnota.
jika belum ada dia akan melanjutkan pengentrian & tidak ada message.
2009/3/11 Frangky <[email protected]>
> Waduh! Menurut saya logika anda untuk mencari tahu nomor nota sudah
> pernah ada atau belum, ribet banget.
>
> Ngapain harus ketik “ribuan” baris code hanya untuk mengecek sudah ada
> nomor nota tersebut atau belum.
>
> Lebih gampangnya pada field No_nota, anda pasang primary key.
>
>
>
>
>
> *From:* [email protected] [mailto:
> [email protected]] *On Behalf Of *•SetyT•
> *Sent:* 11 Maret 2009 9:30
> *To:* [email protected]; [email protected]
> *Subject:* [Programmer-VB] [ASK] Dobel Record
>
>
>
> Pagi master semua,
>
> saya ada sedikit problem nih, maklum pemula :)
> Begini saya mencoba menyimpan data nomor nota, begitu nomor nota kesimpan,
> kita masukin lagi nomor nota tesebut,
> Supaya nomor nota tersebut tidak dobel, gimana ya caranya.
>
> Kesalahan yg muncul seperti dibawah.
>
> Run time error \3021'
>
> either BOF or EOF is true, or the current record has been deleted.
> request operation requires a current record
>
> Saya mencoba membuat perintah seperti dibawah, database yg digunakan mysql.
>
> Private Sub Text1_lostfocus()
> If Text1.Text = "" Then Exit Sub
> SCari = "select * from data where No_nota= '" + Trim(Text1.Text) + "'"
> Set RCari = New ADODB.Recordset
> RCari.Open SCari, CN, adOpenKeyset, adLockReadOnly
> If RCari.RecordCount <> 0 Then
> If RCari("no_nota") = Text1.Text Then
> MsgBox "Nomor Sudah Dipakai", vbOKOnly, "PERHATIAN"
> Text1.SetFocus
> End If
> Exit Sub
> End If
> RCari.Close
> Set RCari = Nothing
> End Sub
>
>
> Mohon bantuannya rekan-rekan.
> Makasih
>
> SH
>
>
>
>
> No virus found in this incoming message.
> Checked by AVG - www.avg.com
> Version: 8.0.237 / Virus Database: 270.11.9/1989 - Release Date: 03/07/09
> 18:43:00
>
>
>