Hi There
I am trying to stop the users of entering duplicate values in a textBox control called (InvoiceID).
I came up with following codes, But the do not work for me at the time, Any suggestion?
Here are the codes, that I tried;
Private Sub InvoiceID100_BeforeUpdate(Cancel As Integer)
Dim Msg As String, Style As Integer, Title As String
Dim DL As String, Criteria As String
DL = vbNewLine & vbNewLine
Criteria = "[InvoiceID100] = " & Me.InvoiceID100.Value
'Or Incase of Text or Nchar data type'
Criteria = "[InvoiceID100] = ' " & Me.InvoiceID100.Value & " ' "
If Not IsNull(DLookup("[InvoiceID100]", "[TableSales]", "[Criteria]") Then 'Or'
If Not IsNull(DLookup("[InvoiceID100]", "[TableSales]", "Criteria")) Then
'Or'
If Not IsNull(DLookup("[InvoiceID100]", "[TableSales]", Criteria)) Then
Msg = "InvoiceId Has Been Issued Allready, Try Another One"
Style = vbCritical + vbOKOnly
Title = "Duplicate Invoice ID Error! . . ."
MsgBox Msg, Style, Title
Cancel = True
End If
End Sub
But no success,
The Data Type of InvoiceID100 was originally nchar,
I tried numeric with the first selection of above Criteria, No success
I should mention, that the InvoiceId100 Lostfocus events
Works fine for both nchar and Numeric data type selection, and the MsgBox pops up,
But for the case of Data type to be text, The LostFocus events works a little strange and msgBox Pops Up even if I have entered some value for it.
Best regards
Sanan
I am trying to stop the users of entering duplicate values in a textBox control called (InvoiceID).
I came up with following codes, But the do not work for me at the time, Any suggestion?
Here are the codes, that I tried;
Private Sub InvoiceID100_BeforeUpdate(Cancel As Integer)
Dim Msg As String, Style As Integer, Title As String
Dim DL As String, Criteria As String
DL = vbNewLine & vbNewLine
Criteria = "[InvoiceID100] = " & Me.InvoiceID100.Value
'Or Incase of Text or Nchar data type'
Criteria = "[InvoiceID100] = ' " & Me.InvoiceID100.Value & " ' "
If Not IsNull(DLookup("[InvoiceID100]", "[TableSales]", "[Criteria]") Then 'Or'
If Not IsNull(DLookup("[InvoiceID100]", "[TableSales]", "Criteria")) Then
'Or'
If Not IsNull(DLookup("[InvoiceID100]", "[TableSales]", Criteria)) Then
Msg = "InvoiceId Has Been Issued Allready, Try Another One"
Style = vbCritical + vbOKOnly
Title = "Duplicate Invoice ID Error! . . ."
MsgBox Msg, Style, Title
Cancel = True
End If
End Sub
But no success,
The Data Type of InvoiceID100 was originally nchar,
I tried numeric with the first selection of above Criteria, No success
I should mention, that the InvoiceId100 Lostfocus events
Works fine for both nchar and Numeric data type selection, and the MsgBox pops up,
But for the case of Data type to be text, The LostFocus events works a little strange and msgBox Pops Up even if I have entered some value for it.
Best regards
Sanan