Re: Newbie - Creating ms access table from Visual Basic

Tech-Archive recommends: Fix windows errors by optimizing your registry

From: Val Mazur (group51a_at_hotmail.com)
Date: 08/19/04


Date: Thu, 19 Aug 2004 18:18:31 -0400

Hi,

This is one more reason to use ADO library directly instead of control,
because in your case you do not need it. Each control will open its own
connection, but it will be opened only in a case if your Data control
returns some data, like SELECT SQL statement. If you do not want to use ADO
library, then you could check connection of the recordset using next kind of
code

if Not Adodc1.Recordset Is Nothing then
    if Adodc1.Recordset.ActiveConnection.State=adStateOpen then
        'you have an opened connection
    endif
endif

-- 
Val Mazur
Microsoft MVP
"Bikrant Neupane" <bikrant_ml@wlink.com.np> wrote in message 
news:ehurUdOhEHA.3016@tk2msftngp13.phx.gbl...
> Val Mazur wrote:
>> Hi,
>>
>> I believe it is not enough. CREATE TABLE belongs to the Data Definition 
>> language and it does not select any data. That means you cannot use it to 
>> open recordset (what you are trying to do in your code). Instead you need 
>> to use
>> Execute method of ADO Connection or command to execute this statement, 
>> not Open method of the recordset and option should be adCmdText, not 
>> adCmdTable
>>
>> MyConnection.Execute sqlCreateTable, , adCmdText
>>
>
> Hi,
> I have tried this: sqlCreateTable = " Create table record ( colour 
> text(15) )"
> Adodc1.Recordset.Source = sqlCreateTable
> Adodc1.Recordset.Open
>
> and it did work for me. The command did get executed, however the 
> connection was not open.  Instead  I again did:
>
> Adodc1.Recordset.Source = "Select * from record"
> Adodc1.Recordset.Open
>
> and now I can use the connection.
>
> Also,next problem,I have not been able to test if a connection is already 
> open or closed. If i try to close already closed connection then I get an 
> error. How do i test if a connection is open or closed??
>
> Thanks,
> Bikrant
>
> 


Relevant Pages

  • Re: ADO control and SQL Session
    ... I defined my ADO in code Dimc xConnection As New ADODB.Connection ... I drag and drop the ADO control to a user form. ... I close the ADO record set connection ... The ADODC control exposes a .recordset property that is a reference to the ...
    (microsoft.public.vb.controls)
  • Re: -2147467259 Unspecified Error
    ... With ADO "classic" you don't have as much control. ... you might try changing the Connection string (change the ... "Terry" wrote in message ...
    (microsoft.public.data.ado)
  • Re: ADO control and SQL Session
    ... In my testing, if I open a VBA form with ADO control, sp_who ... I closed the form,reopen it, the number of sql session ... I close the ADO record set connection ...
    (microsoft.public.vb.controls)
  • Re: Newbie - Creating ms access table from Visual Basic
    ... This is one more reason to use ADO library directly instead of control, ... connection, but it will be opened only in a case if your Data control ... If you do not want to use ADO ... >> not Open method of the recordset and option should be adCmdText, ...
    (microsoft.public.vb.database)
  • Re: if did Endora peer at first all the crops? We cant conceal constables unless Winifred will grea
    ... Let's cater unlike the dark natures, ... it will thereafter control the romance. ... in connection with me it's ... dependent wood won't pull before I relate it. ...
    (sci.crypt)