Results 1 to 10 of 10

Thread: OpenRecordset problem

  1. #1

    Thread Starter
    New Member
    Join Date
    Nov 2000
    Posts
    4

    Angry

    I have a small problem. I'm trying to make a small prototype of a system I made in Ms access for a presentation.
    Well basically I have this problem with record set in a small function

    Private Sub Varenrliste_Change()


    Dim Resultat As Recordset
    Dim Dbs As Database

    Set Dbs = OpenDatabase("c:\My documents\presentation.mdb")
    Set Resultat = Dbs.OpenRecordset("SELECT * FROM Vare WHERE Vare.Varenr=Varenrliste.Text;")

    Varenavntext.Text = Resultat.Fields("Varenavn")
    Varebeskrivelsetext.Text = Resultat.Fields("Varebeskrivelse")
    Varepristext.Text = Resultat.Fields("Varepris")

    Resultat.Close
    Dbs.Close

    End Sub


    Varenr is an integer and so is Varenrtext.text
    however everytime I try to compile it says:

    Run-time error 3061:
    Too few parameters. Expected n.

    can anybody please help me

  2. #2

    Thread Starter
    New Member
    Join Date
    Nov 2000
    Posts
    4
    Come one u guy. All I need is someone to help me out

  3. #3
    _______ HeSaidJoe's Avatar
    Join Date
    Jun 1999
    Location
    Canada
    Posts
    3,946

    <?>

    Code:
    'try adding this and change your set Resultat to the one here 
    Dim myString as string
    myString = Text1.text
    
    Set Dbs = OpenDatabase("c:\My documents\presentation.mdb") 
    
    'the quotes are single double & myString double singel
    
    Set Resultat = Dbs.OpenRecordset("SELECT * FROM Vare WHERE Vare.Varenr='" & myString & "'")
    "A myth is not the succession of individual images,
    but an integerated meaningful entity,
    reflecting a distinct aspect of the real world."

    ___ Adolf Jensen

  4. #4

    Thread Starter
    New Member
    Join Date
    Nov 2000
    Posts
    4
    HeSaidJoe: That doesn't work. says that datatype aren't correct

  5. #5
    Lively Member
    Join Date
    Aug 2000
    Location
    Australia
    Posts
    82
    If your Vare.Varenr field is an integer then try this

    Set Resultat = Dbs.OpenRecordset("SELECT * FROM Vare WHERE Vare.Varenr='" & Val(Varenrliste.Text) & "'")

    OR

    Declare a integer variable to take the result of Val(Varenrliste.Text)
    Then set your SQL statement to read

    Set Resultat = Dbs.OpenRecordset("SELECT * FROM Vare WHERE Vare.Varenr= " & MyIntVariable)

    Hope this helps

    Adrian.

  6. #6
    Fanatic Member Gaffer's Avatar
    Join Date
    Nov 2000
    Location
    London
    Posts
    828
    Replace

    Set Resultat = Dbs.OpenRecordset("SELECT * FROM Vare WHERE Vare.Varenr=Varenrliste.Text;")

    With

    Set Resultat = Dbs.OpenRecordset("SELECT * FROM Vare WHERE Vare.Varenr=” & Varenrliste.Text)


    Hope this helps,

    Gaffer

  7. #7
    New Member
    Join Date
    Nov 2000
    Location
    Pakistan
    Posts
    1

    I need ur help

    Dim db As Database
    Dim rs As Recordset

    Private Sub Form_Load()
    Set db = OpenDatabase("c:\fdb1.mdb")
    Set rs = db.OpenRecordset("people")

    End Sub

    but when i run this it give me the message that unrecognised formate

    pls help me
    adnan

    **************************
    Adnan nazir
    **************************

  8. #8
    _______ HeSaidJoe's Avatar
    Join Date
    Jun 1999
    Location
    Canada
    Posts
    3,946

    <?>

    Adnan nazir
    Code:
    'try this
    'assuming you have a datacontrol called data1
    Option Explicit
    
    Public cDBName As String, cTblName As String
    
    Public Sub OpenDB()
                   
        cDBName = "c:\fdb1.mdb"
        cTblName = "people"
    
        Data1.DatabaseName = cDBName
        Data1.RecordSource = cTblName
                
     End Sub
    
    Private Sub Form_Load()
    '
          Call OpenDB
    '
          Set db = Workspaces(0).OpenDatabase(cDBName)
          Set rs = db.OpenRecordset(cTblName)
    End Sub
    "A myth is not the succession of individual images,
    but an integerated meaningful entity,
    reflecting a distinct aspect of the real world."

    ___ Adolf Jensen

  9. #9
    _______ HeSaidJoe's Avatar
    Join Date
    Jun 1999
    Location
    Canada
    Posts
    3,946
    Geekabyte
    try converting the string

    'the quotes are single double & myString double singel

    Set Resultat = Dbs.OpenRecordset("SELECT * FROM Vare WHERE Vare.Varenr='" & CInt(myString) & "'")

    "A myth is not the succession of individual images,
    but an integerated meaningful entity,
    reflecting a distinct aspect of the real world."

    ___ Adolf Jensen

  10. #10
    Lively Member
    Join Date
    Aug 2000
    Location
    Australia
    Posts
    82

    Adnan Nazir

    Re your "unrecognised format" problem. Are you connecting to an Access 97 or Access 2000 DB?

    If it's Access 2000 then use the Forum Search to read thru the responses on what you need to do in order to connect to Access 2000.

    Cheers
    Adrian

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