chrisjames25
Registered User.
- Local time
- Today, 15:15
- Joined
- Dec 1, 2014
- Messages
- 404
Hi I am trying to do an if statment testing whether a dcount returns a value greater than 0
WHen i enter a variable in Txt_NewTier1 that i know exists in the table i am referencing nothing fires.
I am using defined terms in the code rather than hard coding "Tbl_Category" and "Category" as i have created this form so that i can replicate it for another purpose i.e Add Supplier as opposed to add Category by just changing the following code with the form:
WOuld simply have to change the top two defined strings to Supplier. Obv this is assuming i have kept naming conventions correct in all tables and fields.
Code:
test = StrTier1
test2 = "Tbl_" & test
'If DCount(StrTier1, "Tbl_" & StrTier1, "&StrTier1 & '=" & Txt_NewTier1 & "'") > 0 Then
'If DCount(test, "Tbl_" & test, test = Me.Txt_NewTier1) > 0 Then
If DCount(test, test2, test = Me.Txt_NewTier1) > 0 Then
msg = "This " & StrTier11 & "already exsits!!!"
style = vbOKOnly + vbExclamation
title = StrTier1 & " Duplicate Error"
response = MsgBox(msg, style, title)
WHen i enter a variable in Txt_NewTier1 that i know exists in the table i am referencing nothing fires.
I am using defined terms in the code rather than hard coding "Tbl_Category" and "Category" as i have created this form so that i can replicate it for another purpose i.e Add Supplier as opposed to add Category by just changing the following code with the form:
Code:
Private Function StrTier1() As String
StrTier1 = "Category"
End Function
Private Function StrTier11() As String
StrTier11 = "category"
End Function
'## ON LOAD
'#####################################################
'Tier 1 Settings
'1) Copy and Paste this form
'2) Enter the variable in Tier1Str (Uppercase) and tier1String (lowercase)
'3) Amend the forms data sources and cbo record source and bound controls
'4) Amend the subforms data sources and bound controls
Private Sub Form_Load()
Me.Form.Caption = "Add " & StrTier1
Me.Lbl_Tier1Heading.Caption = StrTier1
Me.Lbl_NewTier1.Caption = "Please enter the new " & StrTier11 & " name:"
Me.Lbl_ConfirmTier1.Caption = "Please re-enter the new " & StrTier11 & " name:"
Me.Cmd_Add.Caption = "Add " & StrTier1
End Sub
WOuld simply have to change the top two defined strings to Supplier. Obv this is assuming i have kept naming conventions correct in all tables and fields.