Results 1 to 15 of 15

Thread: [RESOLVED] Data Retrive in access

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Nov 2005
    Posts
    152

    Resolved [RESOLVED] Data Retrive in access

    Hi all,

    i have one Access on which i have ComboBox when i select the value in combobox it bind the othere control's in subform1 there is one LocationID TextBox on this subform1, now i want to featch (Retrive) value from depends on this LocationID and display it in SubForm2 on same form how can i do this ??

    IS THIS POSIBLE TO RETRIVE THE VALUE FROM DATABASE BY WRITING THE USER DEFINE SELECT STATEMENT ???

    LIKE
    "SELECT * FROM SHIPTOLOCATION WHERE CUSTOMERID IS txtCustomer.Text" ???

    pls Help me regarding this ??
    thanx in advance
    Attached Images Attached Images  
    Last edited by nileshhthakur2004; Mar 16th, 2006 at 04:16 AM. Reason: Attaching the Image
    Nilesh Thakur.

  2. #2
    Frenzied Member KGComputers's Avatar
    Join Date
    Dec 2005
    Location
    Cebu, PH
    Posts
    2,024

    Re: Data Retrive in access

    Hi,

    can you attach the picture of this form/subform?

    CodeBank: VB.NET & C#.NET | ASP.NET
    Programming: C# | VB.NET
    Blogs: Personal | Programming
    Projects: GitHub | jsFiddle
    ___________________________________________________________________________________

    Rating someone's post is a way of saying Thanks...

  3. #3
    Frenzied Member KGComputers's Avatar
    Join Date
    Dec 2005
    Location
    Cebu, PH
    Posts
    2,024

    Re: Data Retrive in access

    IS THIS POSIBLE TO RETRIVE THE VALUE FROM DATABASE BY WRITING THE USER DEFINE SELECT STATEMENT ???

    LIKE
    "SELECT * FROM SHIPTOLOCATION WHERE CUSTOMERID IS txtCustomer.Text" ???
    Yes,it is possible...You may use the concept of DAO or ADO...Access supports ADO and DAO...Some programmers prefer DAO, others prefer ADO...

    CodeBank: VB.NET & C#.NET | ASP.NET
    Programming: C# | VB.NET
    Blogs: Personal | Programming
    Projects: GitHub | jsFiddle
    ___________________________________________________________________________________

    Rating someone's post is a way of saying Thanks...

  4. #4

    Thread Starter
    Addicted Member
    Join Date
    Nov 2005
    Posts
    152

    Re: Data Retrive in access

    Hi KDComputer,

    i have attached the image file .. pls check it

    in this image it show me the customername "National Grocers" and CustomerID = 2
    in subForm name OrderHeader i enter the appropriate CustomerID = 2 now base on this CustomerID 2 i want to retrive the value for OrderNbr i want to find the value using this Select statement

    "select Max(OrderNbr) as MaxNumber from Orderheader where CustomerID = "2""

    and place the MaxNumber in "OrderHeader" sub form's OrderNbr textBox Control ...

    How can i do this ??

    pls help me and also send some sample code or same DB ...

    thanx and regards,
    Nilesh Thakur.

  5. #5

    Thread Starter
    Addicted Member
    Join Date
    Nov 2005
    Posts
    152

    Re: Data Retrive in access

    basicaly i want to Add the new Order For OrderHeader and OrderDetail fro the perticular CustomerID which use select from DropDown....
    else sugest me any othere way...

    thanx and regards,
    Nilesh Thakur.

  6. #6
    Frenzied Member KGComputers's Avatar
    Join Date
    Dec 2005
    Location
    Cebu, PH
    Posts
    2,024

    Re: Data Retrive in access

    Hi,

    Have you tried viewing the northwinds database? Basically, your attached jpeg image reflects to Northwinds database....It's included in the visual studio package..Have you downloaded my simple search program in your previous thread regarding access forms?


    CodeBank: VB.NET & C#.NET | ASP.NET
    Programming: C# | VB.NET
    Blogs: Personal | Programming
    Projects: GitHub | jsFiddle
    ___________________________________________________________________________________

    Rating someone's post is a way of saying Thanks...

  7. #7

    Thread Starter
    Addicted Member
    Join Date
    Nov 2005
    Posts
    152

    Re: Data Retrive in access

    hi KGComputer ,

    my Db is not the Northwind and i have used you Sample DB,for search but my requirement is some thing diffrent ....

    pls help me regarding this ...

    Regards and thanx
    Nilesh Thakur.

  8. #8
    Addicted Member
    Join Date
    Feb 2006
    Location
    Hyderabad, India
    Posts
    233

    Re: Data Retrive in access

    I hope this helps . This is code using ado.
    You have to add reference to Microsoft ActiveX Data Objects 2.5 library in
    Project > References

    VB Code:
    1. dim conn as adodb.connection
    2. dim rs as adodb.recordset
    3. set conn = new adodb.connection
    4. with conn
    5.    .connectionstring  = "Provider  = Microsoft.Jet.OLEDB.4.0"; _
    6.                             & "Data Source = 'YOur database name and path"
    7.    .open
    8. end with
    9.  
    10. set rs=new adodb.recordset
    11. rs.open "select Max(OrderNbr) as MaxNumber from Orderheader where CustomerID = '2'", conn,adopendynaset,adopenreadonly,adcmdtext
    12. yourformname.yourtextbox.text = rs("MaxNumber")

    I am assuming that customer id is a text data type
    I am new to ado myself. You might to make some changes to adopendynaset and adopenradonly.
    Good luck.

  9. #9

    Thread Starter
    Addicted Member
    Join Date
    Nov 2005
    Posts
    152

    Re: Data Retrive in access

    hi srisa,

    thank you for your help , i have tried your code but it won't work , it show me error on this line as below..

    rs.open "select Max(OrderNbr) as MaxNumber from Orderheader where CustomerID = '2'", conn,adopendynaset,adopenreadonly,adcmdtext

    the Error is
    "
    Run-time error '3709':
    The connection cannot be used to perform this operation.It is either closed or invalid in this context."

    pls help me if any one know how to do this ???

    thanx and regards,
    Nilesh Thakur.

  10. #10
    Addicted Member
    Join Date
    Feb 2006
    Location
    Hyderabad, India
    Posts
    233

    Re: Data Retrive in access

    It would be easy if you could post the code. The exact connection string that you are using. By the way which version of access are you using?

  11. #11

    Thread Starter
    Addicted Member
    Join Date
    Nov 2005
    Posts
    152

    Re: Data Retrive in access

    hi srisa,

    i am going to post my code here i am using Access 2000

    and code is as follows

    Private Sub OrderNbr_Change()

    Dim conn As adodb.Connection
    Dim rs As adodb.Recordset
    Set conn = New adodb.Connection


    With conn
    .ConnectionString = "Provider=Microsoft.Jet.OLEDB.3.51;Persist Security
    Info=False;Data Source=C:\Documents and
    Settings\Administrator\Desktop\Joriki 02202006\Joriki_new_03_13_06.mdb;"
    conn.Open
    End With

    Set rs = New adodb.Recordset
    rs.Open "select Max(OrderNbr) as MaxNumber from Orderheaders where CustomerID
    = " & OrderNbr.Text & ", conn, adOpenStatic , adLockOptimistic"

    MsgBox rs("MaxNumber")

    End Sub

    pls help me Regarding this ..

    thanx and regards,
    Nilesh Thakur.

  12. #12
    Addicted Member
    Join Date
    Feb 2006
    Location
    Hyderabad, India
    Posts
    233

    Re: Data Retrive in access

    As far as I know , for ms-access 2000, jetoledb4.0 is used not 3.51
    change this part to
    VB Code:
    1. With conn
    2. .ConnectionString = "Provider=Microsoft.Jet.OLEDB.3.51;Persist Security
    3. Info=False;Data Source=C:\Documents and
    4. Settings\Administrator\Desktop\Joriki 02202006\Joriki_new_03_13_06.mdb;"
    5. conn.Open
    6. End With

    to this
    VB Code:
    1. With conn
    2. .ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;" _
    3.                    & "Persist Security Info=False;" _
    4.                    & "Data Source=C:\Documents and Settings\Administrator\Desktop\Joriki 02202006\Joriki_new_03_13_06.mdb;"
    5. .Open
    6. End With

    And this
    VB Code:
    1. rs.Open "select Max(OrderNbr) as MaxNumber from Orderheaders where CustomerID
    2. = " & OrderNbr.Text & ", conn, adOpenStatic , adLockOptimistic"

    to this
    VB Code:
    1. rs.Open "select Max(OrderNbr) as MaxNumber from Orderheaders where CustomerID = '" & OrderNbr.Text & "'" _
    2.          , conn, adOpenStatic , adLockOptimistic

  13. #13

    Thread Starter
    Addicted Member
    Join Date
    Nov 2005
    Posts
    152

    Re: Data Retrive in access

    hi sirsa,

    thank you very much my code is working now, but there is one problem as you can
    see in connection string i gave the path of my DB as hard code
    like "C:\Documents and Settings\Administrator\Desktop\Joriki.mdb"

    when i place my DB on othere PC it show me error DB not found in VB we Can use
    App.Path & "\UPSThermalLabels.mdb"

    can we use any such a map path function in access also ??

    so DB will Run at any PC and on any Location ??

    Thanx and regards,
    Nilesh Thakur.

  14. #14
    Addicted Member
    Join Date
    Jun 2002
    Location
    Brugge, Belgium
    Posts
    208

    Re: Data Retrive in access

    Hello,

    There are several ways in working from different locations.

    I don't think the app path will work here. I've been looking at this for another project I'm working on.

    One way to work is to use a configuration file on the local pc that stores the path of the main db. This file can be read during startup and stored in a global variable.

    Another way is to use linked tables in access. During start up you just need to check the link-path. If the path changes you get a popup asking you for the database location.

    I've attached some code for refreshing the links.
    J
    Attached Files Attached Files

  15. #15
    Addicted Member
    Join Date
    Feb 2006
    Location
    Hyderabad, India
    Posts
    233

    Re: Data Retrive in access

    Glad to know that I could be of some help to someone. That lets me know that I know something.
    I don't know anything about accessing remote databases. So I cannot be of much help there.
    Searching the forum might lead you to something.
    Last edited by srisa; Mar 22nd, 2006 at 05:12 AM. Reason: forgot something basic

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