Perfect, that did the trick, thank you so much.....
:
You can try
DoCmd.RunSQL "DELETE tblDescAccount.* FROM tblDescAccount WHERE" _
& "[LoanNumber] = '" & Me.[txtLoanNumber] & "'" _
& "And [EmployeeID] = " & Me.[cmbENames] & "" _
& "And [LoanDate] >= #" & Me.[txtBeginDate] & "#" _
& "And [LoanDate] <= #" & Me.[txtEndDate] & "#"
Or, you can try
DoCmd.RunSQL "DELETE tblDescAccount.* FROM tblDescAccount WHERE" _
& " [LoanNumber] = '" & Me.[txtLoanNumber] & "'" _
& " And [EmployeeID] = " & Me.[cmbENames] & "" _
& " And [LoanDate] Between #" & Me.[txtBeginDate] & "#" _
& " And #" & Me.[txtEndDate] & "#"
--
HTH, Good Luck
BS"D
:
Ofer I actually figured it out, I did twick sql statement but Am not sure how
I can use between txtbegindate and txtenddate
Private Sub cmdDeleteLN_Click()
If DCount("*", "[tblDescAccount]", "[LoanNumber] ='" & Me.[txtLoanNumber] &
"'") > 0 Then
DoCmd.SetWarnings False
DoCmd.RunSQL "DELETE tblDescAccount.* FROM tblDescAccount WHERE" _
& "[LoanNumber] = '" & Me.[txtLoanNumber] & "'" _
& "And [EmployeeID] = " & Me.[cmbENames] & "" _
& "And [LoanDate] = #" & Me.[txtBeginDate] & "#" _
& "And [LoanDate] = #" & Me.[txtEndDate] & "#"
DoCmd.SetWarnings True
MsgBox "Record has been deleted"
Else
MsgBox "The Loan Number entered " & [txtLoanNumber] & " was not
found", vbInformation, "No such Loan Number"
End If
:
Can you post the full code?
--
HTH, Good Luck
BS"D
:
Ofer this will only delete where the loan number is equal to what I have
typed in the txtbox, including the records that I did not want to delete...
I added a combobox that contains empolyee names(cmbENames, and 2 text boxes
one for begin date(txtBeginDate) and the other for end date(txtEndDate), how
will code the delete code the delete statement to add those new textboxes
:
Check the data type of the fields, the text fields shouldn't single quote
before and after and a number should have none, so if the LoanNumber field
is number, then try
If DCount("*", "[tblDesAcct]", "[LoanNumber] = " & Me.[txtLoanNumber] & "
And [EmployeeID] = " & Me.[cmbENames].Column(1) & " And [LoanDate] = #" &
Me.[txtBeginDate] & "#") > 0 Then
Or if the EmployeeID field is text then try
If DCount("*", "[tblDesAcct]", "[LoanNumber] = '" & Me.[txtLoanNumber] & "'
And [EmployeeID] = '" & Me.[cmbENames].Column(1) & "' And [LoanDate] = #" &
Me.[txtBeginDate] & "#") > 0 Then
--
HTH, Good Luck
BS"D
:
Ofer, I have tried, but am getting a datatype mismatch this is how my dlookup
looks like: (I did not add yet the between date yet)
If DCount("*", "[tblDesAcct]", "[LoanNumber] = '" & Me.[txtLoanNumber] & "'"
And _
"[EmployeeID] = " & Me.[cmbENames].Column(1) And _
"[LoanDate] = #" & Me.[txtBeginDate] & "#") > 0 Then
:
Not sure about the right names but it should be something like
If DCount ("*", "[TableName]","[loan number] = " & Me.[txtLoannumber] & "
And [TextField] = '" & Me.[TextField] & "' And [DateField] = #" &
Me.[DateField] & "#") > 0
Then
Write delete code here
MsgBox "Record has deleted"
Else
MsgBox "No Reord found"
End If
The same criteria should e for the delete statement
--
HTH, Good Luck
BS"D
:
Thanks ofer That worked perfect, I noticed that in my table, the LoanNumber
could be more than one, so I added a few more textboxes that would "filter"
the right information. I added a combobox that contains empolyee
names(cmbENames, and 2 text boxes one for begin date(txtBeginDate) and the
other for end date(txtEndDate), how will code the delete code to add those
new textboxes
:
Try
If DCount ("*", "[TableName]","[loan number] = " & Me.[txtLoannumber]) > 0
Then
Write delete code here
MsgBox "Record has deleted"
Else
MsgBox "No Reord found"
End If
--
HTH, Good Luck
BS"D
:
Thanks Ofer, that worked, I have another question on top of that, I would
like to inform the user that the records has been deleted if the record
already existed, or if the user entered a loannumber that did not exist, i
would like to inform the user that the loan number entered does not exixt,
how do I add that?
:
Try something like, but not before you back up your data base
Docmd.SetWarnings False
Docmd.RunSQL "DELETE TableName.* FROM TableName WHERE [loan number] = " &
Me.[txtLoannumber]
Docmd.SetWarnings True
========================
If the "loan number" field is text type then try
Docmd.SetWarnings False
Docmd.RunSQL "DELETE TableName.* FROM TableName WHERE [loan number] = '" &
Me.[txtLoannumber] & "'"
Docmd.SetWarnings True
--
HTH, Good Luck
BS"D
:
I have a unbound form, that contains unbound text box.
The txtLoanNumber is the unbound Text Box
there is a button that is be used to delete a record from the table
tblDetAccount based on the entry in txtLoanNumber
How do I code it so that it deletes the record where the loan number is
equal to txtLoannumber.