Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Microsoft Office > Access and Access VBA > Access VBA
|
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
 
Old August 11th, 2004, 08:48 AM
Authorized User
 
Join Date: Apr 2004
Posts: 45
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to lguzman
Default 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]
 
Old August 11th, 2004, 03:19 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,151
Thanks: 2
Thanked 14 Times in 14 Posts
Send a message via ICQ to SerranoG Send a message via AIM to SerranoG
Default

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
 
Old August 12th, 2004, 10:19 AM
Authorized User
 
Join Date: Apr 2004
Posts: 45
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to lguzman
Default

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]
 
Old August 12th, 2004, 10:31 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,151
Thanks: 2
Thanked 14 Times in 14 Posts
Send a message via ICQ to SerranoG Send a message via AIM to SerranoG
Default

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
 
Old August 12th, 2004, 12:32 PM
Authorized User
 
Join Date: Apr 2004
Posts: 45
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to lguzman
Default

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]
 
Old August 12th, 2004, 01:27 PM
Authorized User
 
Join Date: Apr 2004
Posts: 45
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to lguzman
Default

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]
 
Old August 12th, 2004, 01:39 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,151
Thanks: 2
Thanked 14 Times in 14 Posts
Send a message via ICQ to SerranoG Send a message via AIM to SerranoG
Default

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
 
Old August 12th, 2004, 02:17 PM
Authorized User
 
Join Date: Apr 2004
Posts: 45
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to lguzman
Default

Same thing. I still get the "MTLACCOUNTING".

[LGuzman]
 
Old August 12th, 2004, 02:19 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,151
Thanks: 2
Thanked 14 Times in 14 Posts
Send a message via ICQ to SerranoG Send a message via AIM to SerranoG
Default

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
 
Old August 12th, 2004, 03:20 PM
Authorized User
 
Join Date: Apr 2004
Posts: 45
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to lguzman
Default

Checked. No space. Same issue.

[LGuzman]





Similar Threads
Thread Thread Starter Forum Replies Last Post
How do I delete a record from a form? dstein4d Access VBA 8 August 24th, 2007 12:09 PM
Delete a record row, not just the record. Coby Access VBA 1 April 30th, 2007 06:29 AM
automatic record delete. joeore Beginning PHP 5 April 29th, 2004 11:27 AM
Can't delete record Trojan_uk SQL Server 2000 3 November 27th, 2003 01:03 PM
Delete record but how? scifo Beginning PHP 3 August 1st, 2003 12:14 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.