Private
Sub
cmdOkay_Click()
On
Error
GoTo
Mldg
Dim
strSQL
As
String
Dim
intAnzahl
As
Integer
Dim
db
As
Database
Dim
rs
As
Recordset
Dim
strBestNr
As
String
Dim
intI
As
Integer
Dim
strMsg
As
String
strBestNr = Forms!PopFrmKorrBestNr!KorrBestNr
If
strBestNr = Forms!frmBestellungen.BestNr
Then
MsgBox
"Sie verwenden bereits die BestNr: "
& strBestNr
Exit
Sub
End
If
Set
db = CurrentDb()
strSQL =
" SELECT * FROM tblBestellungen WHERE BestNr = '"
& strBestNr &
"'"
Set
rs = db.OpenRecordset(strSQL, dbOpenSnapshot)
If
rs.RecordCount = 0
Then
MsgBox
"Okay"
, vbOKOnly
Forms!frmBestellungen!BestNr = strBestNr
Forms!frmBestellungen.Refresh
Forms!PopFrmKorrBestNr.SetFocus
DoCmd.Close
Forms!frmBestellungen!KdNr.SetFocus
Exit
Sub
End
If
intAnzahl = rs.RecordCount
For
intI = 1
To
intAnzahl
strMsg =
"Leider existiert die Nummer "
& strBestNr &
" bereits:"
& vbCr & _
"Für die KdNr: "
& rs!KdNr
Next
rs.Close
If
intI >= 1
Then
MsgBox strMsg, vbOKOnly
Exit
Sub
End
If
Mldg:
MsgBox Err.Description
End
Sub