PC Review


Reply
Thread Tools Rate Thread

the best way to talk to MS ACCESS

 
 
Bre-x
Guest
Posts: n/a
 
      1st Feb 2010
Hi,

On ms excel I have a sub to send a sql command to ms access

Dim objAcc As Object
Set objAcc = CreateObject("Access.Application")
objAcc.OpenCurrentDatabase "D:\1CNC\APPS\CNC_newapp.mdb"
With objAcc.Application
.Visible = False
'.DoCmd.RunMacro ("Macro1")
.DoCmd.RunSQL "DELETE FROM ttools where tid=7878 and pid=4324"
.DoCmd.Quit
End With

Is the best way to do it?

The db in question will be always open and that particular table will be
always open

Thank you all!!!

Bre-x


 
Reply With Quote
 
 
 
 
Douglas J. Steele
Guest
Posts: n/a
 
      1st Feb 2010
If all you're trying to do is delete data from the mdb file, there's no need
to instantiate another instance of Access.

Try simply

DoCmd.RunSQL "DELETE FROM [;Database=D:\1CNC\APPS\CNC_newapp.mdb].ttools
where tid=7878 and pid=4324"

or (better in my opinion, since it doesn't pop up confirmation windows, plus
will raise a trappable error if something goes wrong)

CurrentDb.Execute "DELETE FROM
[;Database=D:\1CNC\APPS\CNC_newapp.mdb].ttools where tid=7878 and pid=4324",
dbFailOnError

--
Doug Steele, Microsoft Access MVP
http://www.AccessMVP.com/DJSteele
(no e-mails, please!)

"Bre-x" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Hi,
>
> On ms excel I have a sub to send a sql command to ms access
>
> Dim objAcc As Object
> Set objAcc = CreateObject("Access.Application")
> objAcc.OpenCurrentDatabase "D:\1CNC\APPS\CNC_newapp.mdb"
> With objAcc.Application
> .Visible = False
> '.DoCmd.RunMacro ("Macro1")
> .DoCmd.RunSQL "DELETE FROM ttools where tid=7878 and pid=4324"
> .DoCmd.Quit
> End With
>
> Is the best way to do it?
>
> The db in question will be always open and that particular table will be
> always open
>
> Thank you all!!!
>
> Bre-x
>



 
Reply With Quote
 
Bre-x
Guest
Posts: n/a
 
      1st Feb 2010
Thank you for answering my post!!

I am not only going to delete records but also modify some information
"UPDATE......"

on MS Excel I have modified my sub

Sub Temp()
DoCmd.RunSQL "DELETE FROM [;Database=D:\1CNC\APPS\CNC_newapp.mdb].ttools
where tid=7878 and pid=4324"
end sub

I get an error: Run-time 424 Object requiered.

Thanks again!!!







"Douglas J. Steele" <NOSPAM_djsteele@NOSPAM_gmail.com> wrote in message
news:%23uMv$(E-Mail Removed)...
> If all you're trying to do is delete data from the mdb file, there's no
> need to instantiate another instance of Access.
>
> Try simply
>
> DoCmd.RunSQL "DELETE FROM [;Database=D:\1CNC\APPS\CNC_newapp.mdb].ttools
> where tid=7878 and pid=4324"
>
> or (better in my opinion, since it doesn't pop up confirmation windows,
> plus will raise a trappable error if something goes wrong)
>
> CurrentDb.Execute "DELETE FROM
> [;Database=D:\1CNC\APPS\CNC_newapp.mdb].ttools where tid=7878 and
> pid=4324", dbFailOnError
>
> --
> Doug Steele, Microsoft Access MVP
> http://www.AccessMVP.com/DJSteele
> (no e-mails, please!)
>
> "Bre-x" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
>> Hi,
>>
>> On ms excel I have a sub to send a sql command to ms access
>>
>> Dim objAcc As Object
>> Set objAcc = CreateObject("Access.Application")
>> objAcc.OpenCurrentDatabase "D:\1CNC\APPS\CNC_newapp.mdb"
>> With objAcc.Application
>> .Visible = False
>> '.DoCmd.RunMacro ("Macro1")
>> .DoCmd.RunSQL "DELETE FROM ttools where tid=7878 and pid=4324"
>> .DoCmd.Quit
>> End With
>>
>> Is the best way to do it?
>>
>> The db in question will be always open and that particular table will be
>> always open
>>
>> Thank you all!!!
>>
>> Bre-x
>>

>
>



 
Reply With Quote
 
Douglas J. Steele
Guest
Posts: n/a
 
      1st Feb 2010
I totally missed the fact that you were trying to call this from Excel.

What you've got is probably appropriate, although you might get better
advice if you ask in an Excel-related newsgroup.

--
Doug Steele, Microsoft Access MVP
http://www.AccessMVP.com/DJSteele
(no e-mails, please!)

"Bre-x" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Thank you for answering my post!!
>
> I am not only going to delete records but also modify some information
> "UPDATE......"
>
> on MS Excel I have modified my sub
>
> Sub Temp()
> DoCmd.RunSQL "DELETE FROM [;Database=D:\1CNC\APPS\CNC_newapp.mdb].ttools
> where tid=7878 and pid=4324"
> end sub
>
> I get an error: Run-time 424 Object requiered.
>
> Thanks again!!!
>
>
>
>
>
>
>
> "Douglas J. Steele" <NOSPAM_djsteele@NOSPAM_gmail.com> wrote in message
> news:%23uMv$(E-Mail Removed)...
>> If all you're trying to do is delete data from the mdb file, there's no
>> need to instantiate another instance of Access.
>>
>> Try simply
>>
>> DoCmd.RunSQL "DELETE FROM [;Database=D:\1CNC\APPS\CNC_newapp.mdb].ttools
>> where tid=7878 and pid=4324"
>>
>> or (better in my opinion, since it doesn't pop up confirmation windows,
>> plus will raise a trappable error if something goes wrong)
>>
>> CurrentDb.Execute "DELETE FROM
>> [;Database=D:\1CNC\APPS\CNC_newapp.mdb].ttools where tid=7878 and
>> pid=4324", dbFailOnError
>>
>> --
>> Doug Steele, Microsoft Access MVP
>> http://www.AccessMVP.com/DJSteele
>> (no e-mails, please!)
>>
>> "Bre-x" <(E-Mail Removed)> wrote in message
>> news:(E-Mail Removed)...
>>> Hi,
>>>
>>> On ms excel I have a sub to send a sql command to ms access
>>>
>>> Dim objAcc As Object
>>> Set objAcc = CreateObject("Access.Application")
>>> objAcc.OpenCurrentDatabase "D:\1CNC\APPS\CNC_newapp.mdb"
>>> With objAcc.Application
>>> .Visible = False
>>> '.DoCmd.RunMacro ("Macro1")
>>> .DoCmd.RunSQL "DELETE FROM ttools where tid=7878 and pid=4324"
>>> .DoCmd.Quit
>>> End With
>>>
>>> Is the best way to do it?
>>>
>>> The db in question will be always open and that particular table will be
>>> always open
>>>
>>> Thank you all!!!
>>>
>>> Bre-x
>>>

>>
>>

>
>



 
Reply With Quote
 
Bre-x
Guest
Posts: n/a
 
      1st Feb 2010
Thanks,

I would like to hear your opinion on this also.
The CNC_newapp.mdb is the front end, I have the CNC_tables.mdb.

so when I call the function it goes to the front end and from it, It goes to
the back end.

Woud it be better if I run my code agains the back end?

Thank you!!!





"Douglas J. Steele" <NOSPAM_djsteele@NOSPAM_gmail.com> wrote in message
news:%(E-Mail Removed)...
>I totally missed the fact that you were trying to call this from Excel.
>
> What you've got is probably appropriate, although you might get better
> advice if you ask in an Excel-related newsgroup.
>
> --
> Doug Steele, Microsoft Access MVP
> http://www.AccessMVP.com/DJSteele
> (no e-mails, please!)
>
> "Bre-x" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
>> Thank you for answering my post!!
>>
>> I am not only going to delete records but also modify some information
>> "UPDATE......"
>>
>> on MS Excel I have modified my sub
>>
>> Sub Temp()
>> DoCmd.RunSQL "DELETE FROM [;Database=D:\1CNC\APPS\CNC_newapp.mdb].ttools
>> where tid=7878 and pid=4324"
>> end sub
>>
>> I get an error: Run-time 424 Object requiered.
>>
>> Thanks again!!!
>>
>>
>>
>>
>>
>>
>>
>> "Douglas J. Steele" <NOSPAM_djsteele@NOSPAM_gmail.com> wrote in message
>> news:%23uMv$(E-Mail Removed)...
>>> If all you're trying to do is delete data from the mdb file, there's no
>>> need to instantiate another instance of Access.
>>>
>>> Try simply
>>>
>>> DoCmd.RunSQL "DELETE FROM [;Database=D:\1CNC\APPS\CNC_newapp.mdb].ttools
>>> where tid=7878 and pid=4324"
>>>
>>> or (better in my opinion, since it doesn't pop up confirmation windows,
>>> plus will raise a trappable error if something goes wrong)
>>>
>>> CurrentDb.Execute "DELETE FROM
>>> [;Database=D:\1CNC\APPS\CNC_newapp.mdb].ttools where tid=7878 and
>>> pid=4324", dbFailOnError
>>>
>>> --
>>> Doug Steele, Microsoft Access MVP
>>> http://www.AccessMVP.com/DJSteele
>>> (no e-mails, please!)
>>>
>>> "Bre-x" <(E-Mail Removed)> wrote in message
>>> news:(E-Mail Removed)...
>>>> Hi,
>>>>
>>>> On ms excel I have a sub to send a sql command to ms access
>>>>
>>>> Dim objAcc As Object
>>>> Set objAcc = CreateObject("Access.Application")
>>>> objAcc.OpenCurrentDatabase "D:\1CNC\APPS\CNC_newapp.mdb"
>>>> With objAcc.Application
>>>> .Visible = False
>>>> '.DoCmd.RunMacro ("Macro1")
>>>> .DoCmd.RunSQL "DELETE FROM ttools where tid=7878 and pid=4324"
>>>> .DoCmd.Quit
>>>> End With
>>>>
>>>> Is the best way to do it?
>>>>
>>>> The db in question will be always open and that particular table will
>>>> be always open
>>>>
>>>> Thank you all!!!
>>>>
>>>> Bre-x
>>>>
>>>
>>>

>>
>>

>
>



 
Reply With Quote
 
Douglas J. Steele
Guest
Posts: n/a
 
      2nd Feb 2010
I doubt you'd see any meaningful difference.

--
Doug Steele, Microsoft Access MVP
http://www.AccessMVP.com/DJSteele
(no e-mails, please!)

"Bre-x" <(E-Mail Removed)> wrote in message
news:%(E-Mail Removed)...
> Thanks,
>
> I would like to hear your opinion on this also.
> The CNC_newapp.mdb is the front end, I have the CNC_tables.mdb.
>
> so when I call the function it goes to the front end and from it, It goes
> to the back end.
>
> Woud it be better if I run my code agains the back end?
>
> Thank you!!!
>
>
>
>
>
> "Douglas J. Steele" <NOSPAM_djsteele@NOSPAM_gmail.com> wrote in message
> news:%(E-Mail Removed)...
>>I totally missed the fact that you were trying to call this from Excel.
>>
>> What you've got is probably appropriate, although you might get better
>> advice if you ask in an Excel-related newsgroup.
>>
>> --
>> Doug Steele, Microsoft Access MVP
>> http://www.AccessMVP.com/DJSteele
>> (no e-mails, please!)
>>
>> "Bre-x" <(E-Mail Removed)> wrote in message
>> news:(E-Mail Removed)...
>>> Thank you for answering my post!!
>>>
>>> I am not only going to delete records but also modify some information
>>> "UPDATE......"
>>>
>>> on MS Excel I have modified my sub
>>>
>>> Sub Temp()
>>> DoCmd.RunSQL "DELETE FROM [;Database=D:\1CNC\APPS\CNC_newapp.mdb].ttools
>>> where tid=7878 and pid=4324"
>>> end sub
>>>
>>> I get an error: Run-time 424 Object requiered.
>>>
>>> Thanks again!!!
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>> "Douglas J. Steele" <NOSPAM_djsteele@NOSPAM_gmail.com> wrote in message
>>> news:%23uMv$(E-Mail Removed)...
>>>> If all you're trying to do is delete data from the mdb file, there's no
>>>> need to instantiate another instance of Access.
>>>>
>>>> Try simply
>>>>
>>>> DoCmd.RunSQL "DELETE FROM
>>>> [;Database=D:\1CNC\APPS\CNC_newapp.mdb].ttools where tid=7878 and
>>>> pid=4324"
>>>>
>>>> or (better in my opinion, since it doesn't pop up confirmation windows,
>>>> plus will raise a trappable error if something goes wrong)
>>>>
>>>> CurrentDb.Execute "DELETE FROM
>>>> [;Database=D:\1CNC\APPS\CNC_newapp.mdb].ttools where tid=7878 and
>>>> pid=4324", dbFailOnError
>>>>
>>>> --
>>>> Doug Steele, Microsoft Access MVP
>>>> http://www.AccessMVP.com/DJSteele
>>>> (no e-mails, please!)
>>>>
>>>> "Bre-x" <(E-Mail Removed)> wrote in message
>>>> news:(E-Mail Removed)...
>>>>> Hi,
>>>>>
>>>>> On ms excel I have a sub to send a sql command to ms access
>>>>>
>>>>> Dim objAcc As Object
>>>>> Set objAcc = CreateObject("Access.Application")
>>>>> objAcc.OpenCurrentDatabase "D:\1CNC\APPS\CNC_newapp.mdb"
>>>>> With objAcc.Application
>>>>> .Visible = False
>>>>> '.DoCmd.RunMacro ("Macro1")
>>>>> .DoCmd.RunSQL "DELETE FROM ttools where tid=7878 and pid=4324"
>>>>> .DoCmd.Quit
>>>>> End With
>>>>>
>>>>> Is the best way to do it?
>>>>>
>>>>> The db in question will be always open and that particular table will
>>>>> be always open
>>>>>
>>>>> Thank you all!!!
>>>>>
>>>>> Bre-x
>>>>>
>>>>
>>>>
>>>
>>>

>>
>>

>
>



 
Reply With Quote
 
David W. Fenton
Guest
Posts: n/a
 
      2nd Feb 2010
"Bre-x" <(E-Mail Removed)> wrote in
news:#(E-Mail Removed):

> The CNC_newapp.mdb is the front end, I have the CNC_tables.mdb.
>
> so when I call the function it goes to the front end and from it,
> It goes to the back end.
>
> Woud it be better if I run my code agains the back end?


I would say use the back end directly, but only if you're using only
tables and not queries stored in the front end.

--
David W. Fenton http://www.dfenton.com/
usenet at dfenton dot com http://www.dfenton.com/DFA/
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Can Access 2000 talk to 97? KevinS Microsoft Access Database Table Design 8 17th Apr 2009 02:34 AM
Talk Talk broadband free for one year ! Abarbarian General 6 13th Feb 2009 03:14 PM
How does Access 'talk' to linked Access tables? Robert_L_Ross Microsoft Access 6 9th Jun 2008 02:36 PM
Opinions requested - Talk Talk Broadband cguil_uk General 5 28th Mar 2008 09:10 AM
ACCESS DB - How do I get .NET to talk Chester West Microsoft ADO .NET 3 20th Nov 2003 03:00 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 02:00 AM.