Access VBADiscuss 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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
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.".
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
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'.