VBA Code Help

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Greetings...

I am getting a complie syntex error with the code listed below! Can someone
please help me with it? The ID Fields are text fields.


CurrentDb.Execute "DELETE FROM tblMovement " & _
"WHERE EmpId = '" & lstNewSupervisor.Column(0) & _
"' AND SupervisorID = " & txtSupervisorID

Thanks!
 
alfiajamel said:
Greetings...

I am getting a complie syntex error with the code listed below! Can
someone please help me with it? The ID Fields are text fields.


CurrentDb.Execute "DELETE FROM tblMovement " & _
"WHERE EmpId = '" & lstNewSupervisor.Column(0) & _
"' AND SupervisorID = " & txtSupervisorID

Thanks!

If both ID fields are text fields then you need quotes around both values.
Currently you only have quotes around the first one.
 
Make sure that the txtSupervisorID and lstNewSupervisor.Column(0) return value.

CurrentDb.Execute "DELETE FROM tblMovement " & _
"WHERE EmpId = '" & lstNewSupervisor.Column(0) & _
"' AND SupervisorID = " & txtSupervisorID

If txtSupervisorID field will be blank you'll get syntax error
 
Thank you for the advice, however, I actually already tried that approach.
How would I accomplish that without the syntax errors? My attempt is posted
below


CurrentDb.Execute "DELETE FROM tblMovement " & _
"WHERE EmpId = '" & lstNewSupervisor.Column(0) & _
"'" AND SupervisorID = '" & txtSupervisorID "'"

I cannot begin to thank you enough for your help!
 
Thank you for the advice, however, I actually already tried that approach.
How would I accomplish that without the syntax errors? My attempt is posted
below


CurrentDb.Execute "DELETE FROM tblMovement " & _
"WHERE EmpId = '" & lstNewSupervisor.Column(0) & _
"'" AND SupervisorID = '" & txtSupervisorID "'"

I cannot begin to thank you enough for your help!

I've separated the single and double quotes so you can see them
better. Remove those spaces in your code.

CurrentDb.Execute "DELETE tblMovement.* FROM tblMovement " _
& "WHERE EmpId = ' " & lstNewSupervisor.Column(0) _
& " ' AND SupervisorID = ' " & txtSupervisorID " ' "
 
I have a methodolgy question! I have some hidden fields on my form that
drive the information. What would be the best way to have those hidden fields
also inserted into my table? Per the code listed below, I have 2 fields
being inserted into tblMovement. How would I insert the hidden fields as
well?

Thanks
 
Greetings...

Would someone please tell me what I am doing wrong?!!??!? I have tried the
quotes and I am still getting a compile error. Both ID fields are text. My
coding is below (at least my attempt at coding):
CurrentDb.Execute "DELETE FROM tblMovement " & _
"WHERE EmpId = '" & lstNewSupervisor.Column(0) & _
"'" AND SupervisorID = '" & txtSupervisorID "'"
 
Try

Would someone please tell me what I am doing wrong?!!??!? I have tried the
quotes and I am still getting a compile error. Both ID fields are text. My
coding is below (at least my attempt at coding):
CurrentDb.Execute "DELETE FROM tblMovement " & _
" WHERE EmpId = '" & lstNewSupervisor.Column(0) & _
"' AND SupervisorID = '" & txtSupervisorID & "'"

**** In the last line you have double quote to much in the beggining, and
missing an & in the end to include the last single quote, and I assume by
your code that both fields SupervisorID and EmpId are text fields, if they
not you'll get a type mismatch, in that case remove the single quote
 
You have been so much help thus far, however, I am just not getting it right!
Would you be willing to type the code out for me?
 
I did in the last post

--
Good Luck
BS"D


alfiajamel said:
You have been so much help thus far, however, I am just not getting it right!
Would you be willing to type the code out for me?
 
Thank you SOOOO much! I didn't see it. I had to copy and paste to make the
font bigger. You have saved me, you just don't know!!!

Thanks again!
 
Back
Top