Results 1 to 4 of 4

Thread: Help -SQL

  1. #1

    Thread Starter
    New Member
    Join Date
    Jul 2000
    Posts
    14
    I amnew in VB and I would appreciate any help
    Can anyone tell me why this argument does not work?

    __________________________
    Dim newID
    Private RS As New ADODB.Recordset

    Set RS = Adodc1.Recordset
    RS.Bookmark = DataGrid1.Bookmark
    newID = RS.Fields("RefID")

    ' Adodc1, RS and Adodc2 work fine
    ' then here is the problem :
    Adodc2.RecordSource = "SELECT Reference.*,_
    Reference.RefID From Reference_
    WHERE (((Reference.RefID)=newID));"
    Adodc2.Refresh
    _________________________________

    When instead of newID I put a number everything is OK. What is the problem with newID?

    Thanks in advance

    emmzou


  2. #2
    Hyperactive Member
    Join Date
    Apr 2000
    Location
    Isle of Man
    Posts
    276
    you will need to add newID to the sql string, like this


    Code:
    Dim newID 
    Private RS As New ADODB.Recordset 
    
    Set RS = Adodc1.Recordset 
    RS.Bookmark = DataGrid1.Bookmark 
    newID = RS.Fields("RefID") 
    
    ' Adodc1, RS and Adodc2 work fine 
    ' then here is the problem : 
    Adodc2.RecordSource = "SELECT Reference.*,_ 
    Reference.RefID From Reference_ 
    WHERE (((Reference.RefID)= "& newID &"));" 
    Adodc2.Refresh
    bear in mind, you may have to put something surrounding newID, eg if it contains text: -
    Code:
    WHERE (((Reference.RefID)= '"& newID & "'));"
    hope this is of some help to you...

  3. #3

    Thread Starter
    New Member
    Join Date
    Jul 2000
    Posts
    14
    I think that my question was rather incomplete. The RefID is the primary key (Autonumber) in an Access database thus it corresponds to a number and not text. As I mentioned when I use the newID in the SQL query this does not work but it runs fine when I put the corresponding number, for example

    Adodc2.RecordSource = "SELECT Reference.*,_
    Reference.RefID From Reference_
    WHERE (((Reference.RefID)= 105));"

    runs fine.

    This is why I suspect that there is a problem with newID.
    Any other idea?

    THANKS for your help


  4. #4

    Thread Starter
    New Member
    Join Date
    Jul 2000
    Posts
    14
    Jimbob

    I gave a second try using:

    "& newID &"

    and now it's OK.

    THANKS a lot

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