By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
425,790 Members | 1,409 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 425,790 IT Pros & Developers. It's quick & easy.

DLookUp function doesn't want to work with my code

P: 13
Expand|Select|Wrap|Line Numbers
  1. Private Sub Command11_Click()
  2. Dim strSQL As String
  3. Dim criteria As Integer
  4. Dim ete As String
  5. Dim row, place As Integer
  6. ete = Me!etenduse_nimi
  7. row = Me!Rida
  8. place = Me!number
  9.  
  10. criteria = DLookup("[broneeringu_id]", "BroneeringudQ", " etenduse_nimi='" & ete & "' AND rida=" & row & " AND number=" & place & " AND Toimumisaeg=" & Me!Toimumisaeg)
  11. strSQL = "DELETE * FROM Broneeringud WHERE broneeringu_id=" & criteria
  12. DoCmd.RunSQL strSQL
  13. End Sub
What seems to be the problem in the code?
ete is string
row is integer
place is integer
Me!Toimumisaeg is date/time and it has date and time in the same field. It gives run-time error 3075.
Apr 30 '12 #1
Share this Question
Share on Google+
4 Replies


Rabbit
Expert Mod 10K+
P: 12,357
When you have a date time field, you need to demarcate it as such by surrounding it with # symbols.
Apr 30 '12 #2

P: 13
Weirdly enough the code goes red and starts popping up messages about the date/time not being a date.
Apr 30 '12 #3

Rabbit
Expert Mod 10K+
P: 12,357
Then I would double check to make sure the field in the table is actually a date data type. And also check that the input is in the correct format.
Apr 30 '12 #4

NeoPa
Expert Mod 15k+
P: 31,418
You also need to handle the situation where Me.Toimumisaeg is Null. In my suggestion I use the Date() function if this value is Null.

Try :
Expand|Select|Wrap|Line Numbers
  1. Criteria = Format(Nz(Me.Toimumisaeg, Date()), "\#m\/d\/yyyy\#")
  2. Criteria = "[etenduse_nimi]='" & ete & "' AND " & _
  3.            "[rida]=" & row & " AND " & _
  4.            "[number]=" & place & " AND " & _
  5.            "[Toimumisaeg]=" & Criteria
  6. Criteria = DLookup("[broneeringu_id]", "BroneeringudQ", Criteria)
Apr 30 '12 #5

Post your reply

Sign in to post your reply or Sign up for a free account.