That's up to you! You design whatever you see fit for your users.
I definitely feel like it'd be easier for me to code a small entry form that opens up that allows a new inventory entry.
That's up to you! You design whatever you see fit for your users.
Well, that's more intuitive. But if the form that's being searched against is the inventory table alone then that same form can be used to add new entries.
Give it some thought and decide the approach you'll take.
Private Sub btnAdd_Click()
Dim strmessage As String
' If there's something in the text box AND it is already in the table, then don't add it
If Len(Me.txtDes & vbNullString) > 0 And DCount("[Designname]", "tblDesignName", "[Designname]='" & Me![txtDes] & "'") > 0 Then
Exit Sub
Else
SQL = "INSERT INTO tblCollection (CollectionName) VALUES ([forms]![frmAddJewelryInventory]![txtcol])"
DoCmd.RunSQL SQL
End If
End Sub
Conditions 1 and 3 are the same. Correct it and we can look at your code.
Ok. Is the criteria going to be applied to a form or a control? You want to:
1. first apply the filter the criteria to the form/control
2. test if it returns any records
3. Use that as your basis for deciding whether to add the record or not.
If Len(Me.txtDes & vbNullString) > 0 And DCount("[CollectionName]", "tblCollection", "[CollectionName]='" & Me![txtCol] & "'") > 0 Then
You're missing my point. Those textboxes are search textboxes used to eventually filter a form right?
Dim blCondition As Boolean
Dim strCriteria As String
blCondition = Len(Me.txtColId & vbNullString) <> 0 And _
Len(Me.txtDesId & vbNullString) <> 0 And _
Len(Me.txtJewId & vbNullString) <> 0
If blCondition = True Then
strCriteria = "[CollectionId] = " & Me.txtColId & " AND " & _
"[DesignId] = " & Me.txtDesId & " AND " & _
"[JewelleryTypeId] = " & Me.txtJewId
If DCount("[CollectionName]", "tblCollection", strCriteria) <> 0 Then
End If
End If
Something like this:
... you should be using the numeric Id not the description.Code:Dim blCondition As Boolean Dim strCriteria As String blCondition = Len(Me.txtColId & vbNullString) <> 0 And _ Len(Me.txtDesId & vbNullString) <> 0 And _ Len(Me.txtJewId & vbNullString) <> 0 If blCondition = True Then strCriteria = "[CollectionId] = " & Me.txtColId & " AND " & _ "[DesignId] = " & Me.txtDesId & " AND " & _ "[JewelleryTypeId] = " & Me.txtJewId If DCount("[CollectionName]", "tblCollection", strCriteria) <> 0 Then End If End If