 |
| Access VBA Discuss using VBA for Access programming. |
Welcome to the p2p.wrox.com Forums.
You are currently viewing the Access VBA section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
|
|
|
|

August 11th, 2004, 08:48 AM
|
|
Authorized User
|
|
Join Date: Apr 2004
Posts: 45
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Trying to delete a record... Can't do it...
Good day all.
Here is some background.
I log on a table the Computer Names of all machines which launch my application.
I would also like to delete the name of the computer when they exit the application.
To that effect on my form Form_Close has the following code:
Dim NBuffer As String
Dim Buffsize As Long
Dim Wok As Long
Dim strComputerName As String
'Dim wrkDefault As Workspace
Dim dbs As Database
Dim rst As Recordset
'Set wrkDefault = DBEngine.Workspaces(0)
Set dbs = CurrentDb
'Set dbs = OpenDatabase("lcdb.mdb")
Set rst = dbs.OpenRecordset("ActiveMachines")
'---------------------------------------------------------------------------------
'------------------------- Establishes Machine Name
Buffsize = 256
NBuffer = Space$(Buffsize)
Wok = api_GetComputerName(NBuffer, Buffsize)
strComputerName = Trim$(NBuffer)
'---------------------------------------------------------------------------------
'------------------------- Deletes the Machine Name
dbs.Execute "DELETE * From " & "ActiveMachines where MachineName = " & "strComputerName;"
dbs.Close
But it doesn't work. It keeps telling me : "Too few parameters. Expected 1.".
Help!
Thanks.
[LGuzman]
__________________
[LGuzman]
|
|

August 11th, 2004, 03:19 PM
|
|
Friend of Wrox
|
|
Join Date: Jun 2003
Posts: 1,151
Thanks: 2
Thanked 14 Times in 14 Posts
|
|
Be careful of double and single quotes:
dbs.Execute "DELETE * FROM ActiveMachines WHERE [MachineName] = '" & strComputerName & "';"
Greg Serrano
Michigan Dept. of Environmental Quality, Air Quality Division
|
|

August 12th, 2004, 10:19 AM
|
|
Authorized User
|
|
Join Date: Apr 2004
Posts: 45
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Greg.
Thank you very much for answering me. It seems to have helped. I still get an error but in the error message I now see the Computer Name.
Now this is the error I get when I use the line you provided me with:
Syntax error in string in query expression'[MachineName] = 'MTLACCOUNTING'.
If I remove the [] of MachineName I get the same error but without the []...
Thanks again Greg. Hope you or anyone else can help me with this one.
[LGuzman]
|
|

August 12th, 2004, 10:31 AM
|
|
Friend of Wrox
|
|
Join Date: Jun 2003
Posts: 1,151
Thanks: 2
Thanked 14 Times in 14 Posts
|
|
Read my code again on the web so you can see proper spacing and quotes. If you read this in e-mail, it'll look odd with the codes showing. Copy and paste it into your code exactly as I have it written.
Code:
dbs.Execute "DELETE * FROM ActiveMachines WHERE [MachineName] = '" & strComputerName & "';"
Greg Serrano
Michigan Dept. of Environmental Quality, Air Quality Division
|
|

August 12th, 2004, 12:32 PM
|
|
Authorized User
|
|
Join Date: Apr 2004
Posts: 45
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Thanks for the prompt response. Copy and paste is what I had done. Nevertheless I repeated the excercise and copied and pasted it again. The exact error message I'm getting is:
Run-Time error '3075':
Syntax error in string in query expression '[MachineName] =
'MTLACCOUNTING'.
[LGuzman]
|
|

August 12th, 2004, 01:27 PM
|
|
Authorized User
|
|
Join Date: Apr 2004
Posts: 45
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
More info...
I clicked on Debug, and it brought me to:
dbs.Execute "DELETE * FROM ActiveMachines WHERE [MachineName] = '" & strComputerName & "';"
While checking the syntax, I placed the cursor on strComputerName and noticed that its value was "MTLACCOUNTINGÂ".
So I got currious, and put the following line right before the above mentioned line: strComputerName="MTLACCOUNTING".
When I did this, it worked. So I think the problem is the  after MTLACCOUNTING.
So the question now would be does anyone know why I get that and more important how can I get rid of it!
Thanks.
[LGuzman]
|
|

August 12th, 2004, 01:39 PM
|
|
Friend of Wrox
|
|
Join Date: Jun 2003
Posts: 1,151
Thanks: 2
Thanked 14 Times in 14 Posts
|
|
How about if you did this? Add the TRIM function to the computer name... that is:
dbs.Execute "DELETE * FROM ActiveMachines WHERE [MachineName] = '" & Trim(strComputerName) & "';"
Greg Serrano
Michigan Dept. of Environmental Quality, Air Quality Division
|
|

August 12th, 2004, 02:17 PM
|
|
Authorized User
|
|
Join Date: Apr 2004
Posts: 45
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Same thing. I still get the "MTLACCOUNTINGÂ".
[LGuzman]
|
|

August 12th, 2004, 02:19 PM
|
|
Friend of Wrox
|
|
Join Date: Jun 2003
Posts: 1,151
Thanks: 2
Thanked 14 Times in 14 Posts
|
|
Make sure there is no space between the " and the ' in the part of the expression that looks like this:
& "';"
Greg Serrano
Michigan Dept. of Environmental Quality, Air Quality Division
|
|

August 12th, 2004, 03:20 PM
|
|
Authorized User
|
|
Join Date: Apr 2004
Posts: 45
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Checked. No space. Same issue.
[LGuzman]
|
|
 |