Results 1 to 8 of 8

Thread: Simple Database Trouble ???

  1. #1

    Thread Starter
    New Member
    Join Date
    Apr 2006
    Posts
    3

    Simple Database Trouble ???

    Hi there all you happy coders

    I'm having a little problem with a simple MS Access database.
    I want my app to search through the database and switch to that record if the result is found.
    This is the Database layout.
    Camera.mdb <--- Database
    -Camera <--- Table
    -Machine <--- Field
    -Camera <--- Field

    I want to click on Command1 to be my action. Text2.txt should be the search bar and the [Machine] field to be the source.
    I have tried:
    Data1.Recordset.FindFirst "Machine Like '" & Text2.Text & "'"
    but to no evail!
    Please help!!
    Thx

  2. #2
    eltiT resU motsuC Static's Avatar
    Join Date
    Oct 2000
    Location
    Rochester, NY
    Posts
    9,390

    Re: Simple Database Trouble ???


    dont use the data control
    use ADO

    you will have much better control over it
    something like this
    VB Code:
    1. 'Add A reference to the Microsoft ActiveX data Object 2.x
    2.  
    3. Dim CNN As New Connection
    4. Private Sub Command1_Click()
    5.     Dim rs As New Recordset
    6.     rs.Open "SELECT [Camera] FROM Camera WHERE Machine Like ='" & text2.Text & "'"
    7.     If Not rs.EOF Then
    8.         Text3 = rs!Camera
    9.     End If
    10.     rs.Close
    11.    
    12. End Sub
    13.  
    14. Private Sub Form_Load()
    15.     CNN.Open "Driver={Microsoft Access Driver (*.mdb)};Dbq=C:\Path\to\Camera.mdb;Uid=;Pwd=;"
    16.     CNN.CursorLocation = adUseClient
    17.     If CNN.State = 0 Then MsgBox "Error Connecting"
    18. End Sub
    SUGGESTION: Change the Field Name or the table name so they do not match
    like change the table to "tblCamera"
    JPnyc rocks!! (Just ask him!)
    If u have your answer please go to the thread tools and click "Mark Thread Resolved"

  3. #3

    Thread Starter
    New Member
    Join Date
    Apr 2006
    Posts
    3

    Re: Simple Database Trouble ???

    Hi there Static

    I have done as u said, but I get an error on running it...

    Compile error:
    Invalid use of New keyword
    ' Dim CNN As New Connection is highlighted

    thx

  4. #4
    eltiT resU motsuC Static's Avatar
    Join Date
    Oct 2000
    Location
    Rochester, NY
    Posts
    9,390

    Re: Simple Database Trouble ???

    di u add the reference?

    Project Menu > References > MS ActiveX Data Objects 2.8 Library
    JPnyc rocks!! (Just ask him!)
    If u have your answer please go to the thread tools and click "Mark Thread Resolved"

  5. #5

    Thread Starter
    New Member
    Join Date
    Apr 2006
    Posts
    3

    Re: Simple Database Trouble ???

    Yip... Readded it but still the same...

    You see, my code with the data control worked on my laptop but not on the pc @ work... It gave me a error

    Class not registered.
    Looking for object with CLSID:{00000020-0000-0010-8000-00AA006D2EA4}

    Run-time error '91:
    Object variable or With block variable not set

  6. #6
    eltiT resU motsuC Static's Avatar
    Join Date
    Oct 2000
    Location
    Rochester, NY
    Posts
    9,390

    Re: Simple Database Trouble ???

    sounds like u might need to re-install VB?

    do u have SP6 as well?
    JPnyc rocks!! (Just ask him!)
    If u have your answer please go to the thread tools and click "Mark Thread Resolved"

  7. #7
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,335

    Re: Simple Database Trouble ???

    Quote Originally Posted by Sparky556
    Hi there Static

    I have done as u said, but I get an error on running it...

    Compile error:
    Invalid use of New keyword
    ' Dim CNN As New Connection is highlighted

    thx
    The correct syntax would be
    VB Code:
    1. Option Explicit
    2.  
    3. Private CNN As ADODB.Connection
    4.  
    5. Private Sub Form_Load()
    6.     Set CNN = New ADODB.Connection
    7.     CNN.Open "Driver={Microsoft Access Driver (*.mdb)};Dbq=C:\Path\to\Camera.mdb;Uid=;Pwd=;"
    8.     CNN.CursorLocation = adUseClient
    9.     If CNN.State = 0 Then MsgBox "Error Connecting"
    10. End Sub

  8. #8
    eltiT resU motsuC Static's Avatar
    Join Date
    Oct 2000
    Location
    Rochester, NY
    Posts
    9,390

    Re: Simple Database Trouble ???

    hmm.. Hack I have always done the New statement like that (well not always but a lot) and it works fine for me?
    JPnyc rocks!! (Just ask him!)
    If u have your answer please go to the thread tools and click "Mark Thread Resolved"

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