Results 1 to 4 of 4

Thread: Access 2007 Form - sqlserver2000

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Jun 2007
    Posts
    94

    Question Access 2007 Form - sqlserver2000

    Hi everybody,

    I am using Access 2007 and i am trying to connect to sql server 2000 from a form in access 2007. I havent done this before, after some search i tried this code, can you advise me if it is correct:


    Dim connsql1 As String
    connsql1 = "test"

    Dim connection1 As SqlClient.SqlConnection

    connection1 = SqlClient.SqlConnection("Data Source=ServerName;Initial Catalog=DatabaseName;User Id=sa;Password=sa")

    Dim myCMD As SqlCommand
    myCMD = "select count(n0_period_no) from plu"
    Text1.Text = myCMD


    First of all i want to get an input from the program that the connection succeded, that is why i run this query and i want to display the result in the textox...


    Any ideas are really appreciated,

    Thanks in advance,
    Best Regards

  2. #2
    Hyperactive Member Davadvice's Avatar
    Join Date
    Apr 2007
    Location
    Glasgow (Scotland)
    Posts
    440

    Re: Access 2007 Form - sqlserver2000

    i would recomend that you use ADO for this connection.

    Search on here for ADO

    and the connections string you need is
    vb Code:
    1. Data Source=myServerAddress;Initial Catalog=myDataBase;User Id=myUsername;Password=myPassword;

    changing the name for Datasource,user, Database and password.

    check out connectionStrings also
    This is Blank

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Jun 2007
    Posts
    94

    Re: Access 2007 Form - sqlserver2000

    Dear All,

    I finally managed to make a connection from Access 2007 form to Sql Server 2000. I am trying to run a simple query to see the result in a textbox, but i get the following error. In the SQL database the field n0_department_no is decimal (5 lenght).

    The code is below any help is appreciated


    Dim ad As adodb.Connection
    Set ad = New adodb.Connection


    Let ad.ConnectionString = "Driver={SQL Server}; Server=ServerName; Trusted_Connection=no; Database=DBName; UID=user ;PWD=pwd"
    ad.Open

    Dim ar As adodb.Recordset
    Set ar = New adodb.Recordset

    ar.Open "select n0_department_no from plu where sz_item_ref_no = 59091", ad, adOpenKeyset, adLockPessimistic

    Text1.Text = ar!sz_item_ref_no



    When i run this program i get the errror in the image, ANy ideas ????


    Thanks in advance,

    Best Regards
    Attached Images Attached Images  

  4. #4
    Discovering Life Siddharth Rout's Avatar
    Join Date
    Feb 2005
    Location
    Mumbai, India
    Posts
    12,001

    Re: Access 2007 Form - sqlserver2000

    Which line gives you the error?
    A good exercise for the Heart is to bend down and help another up...
    Please Mark your Thread "Resolved", if the query is solved


    MyGear:
    ★ CPU ★ Ryzen 5 5800X
    ★ GPU ★ NVIDIA GeForce RTX 3080 TI Founder Edition
    ★ RAM ★ G. Skill Trident Z RGB 32GB 3600MHz
    ★ MB ★ ASUS TUF GAMING X570 (WI-FI) ATX Gaming
    ★ Storage ★ SSD SB-ROCKET-1TB + SEAGATE 2TB Barracuda IHD
    ★ Cooling ★ NOCTUA NH-D15 CHROMAX BLACK 140mm + 10 of Noctua NF-F12 PWM
    ★ PSU ★ ANTEC HCG-1000-EXTREME 1000 Watt 80 Plus Gold Fully Modular PSU
    ★ Case ★ LIAN LI PC-O11 DYNAMIC XL ROG (BLACK) (G99.O11DXL-X)
    ★ Monitor ★ LG Ultragear 27" 240Hz Gaming Monitor
    ★ Keyboard ★ TVS Electronics Gold Keyboard
    ★ Mouse ★ Logitech G502 Hero

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width