Results 1 to 3 of 3
  1. #1
    NancyLoc is offline Novice
    Windows XP Access 2003
    Join Date
    Apr 2012
    Posts
    2

    Question Creating relational links between tables

    I am trying to re-establish links between two tables.
    However, the code underneath seems to cause problems.
    Does someone have an idea what would be the problem ?

    Thanks

    Nancy
    ---------------------

    Private Sub Command1_Click()
    Dim dbs As Database
    Dim rstspain As Recordset
    Dim rstcity As Recordset
    Set dbs = CurrentDb()
    Set rstspain = dbs.OpenRecordset("Spain", dbOpenDynaset)


    Set rstcity = dbs.OpenRecordset("City", dbOpenDynaset)
    rstspain.MoveFirst
    Do While Not rstspain.EOF
    rstcity.MoveFirst
    rstcity.FindFirst cityname = rstspain![cityname] ( tried also " [cityname] = " & rstspain![cityname]" (with same result))
    If rstcity.NoMatch Then
    MsgBox "City not found"
    Else
    rstspain.Edit
    rstspain!city = rstcity!cityID
    rstspain.Update
    End If

    rstspain.MoveNext
    Loop
    MsgBox "Einde"

    End Sub

  2. #2
    ssanfu is offline Master of Nothing
    Windows 2K Access 2000
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    If "rstspain![cityname]" is a text type field, you need to use delimiters. Try:

    Code:
    Private Sub Command1_Click()
       Dim dbs As Database
       Dim rstspain As Recordset
       Dim rstcity As Recordset
    
       Set dbs = CurrentDb()
       Set rstspain = dbs.OpenRecordset("Spain", dbOpenDynaset)
       Set rstcity = dbs.OpenRecordset("City", dbOpenDynaset)
    
       rstspain.MoveFirst
    
       Do While Not rstspain.EOF
          rstcity.MoveFirst
          rstcity.FindFirst "[cityname] = '" & rstspain![cityname] & "'"
          If rstcity.NoMatch Then
             MsgBox "City " & rstspain![cityname] & " not found"
          Else
             rstspain.Edit
             rstspain!city = rstcity!cityID
             rstspain.Update
          End If
    
          rstspain.MoveNext
       Loop
       MsgBox "Einde"
    
    End Sub
    Exploded, the line looks like:

    rstcity.FindFirst "[cityname] = ' " & rstspain![cityname] & " ' "

    (but don't use with the spaces)

  3. #3
    NancyLoc is offline Novice
    Windows XP Access 2003
    Join Date
    Apr 2012
    Posts
    2
    Many thanks for this !
    I should have known ... need a refreshment course ggrggr ...
    Nancy

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Relational tables - again
    By BarbT in forum Access
    Replies: 6
    Last Post: 10-31-2010, 10:28 AM
  2. Relational tables help
    By BarbT in forum Access
    Replies: 5
    Last Post: 10-21-2010, 09:03 AM
  3. Creating Links to Word Docs
    By kingharvest in forum Access
    Replies: 1
    Last Post: 05-19-2010, 10:28 PM
  4. Relating 2 Tables - Relational Problem
    By jeng in forum Database Design
    Replies: 5
    Last Post: 04-01-2010, 09:25 PM
  5. Replies: 1
    Last Post: 03-28-2010, 08:06 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums