Results 1 to 5 of 5
  1. #1
    Ruegen's Avatar
    Ruegen is offline VIP
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jul 2013
    Location
    Australia
    Posts
    1,496

    Converting lookup text field to number for primary

    I have a field in a table that another links into - it's from an old database and they didn't use the primary key.



    I need to convert the text field to a number so it uses the primary key from the table called 'tblBanks'

    Is there a batch way to convert the text in those fields to their corresponding primary key on the other table? There's about 30 and I need to do this a few times for testing reasons and I don't know how to get an update query to update multiples of the same field.

    (I require keeping the table data)

    If it makes it any easier this is what I hope to do but for more than just one of the same field...
    Click image for larger version. 

Name:	Capture.JPG 
Views:	11 
Size:	15.4 KB 
ID:	13732

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,931
    Do these tables presently have a common value that can be used to join them?
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    Ruegen's Avatar
    Ruegen is offline VIP
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jul 2013
    Location
    Australia
    Posts
    1,496
    Yeah, there is a text field in "tblBanks" that for the large majority is the same as in the other text field in "tblSchools" that I want to convert to a number field (except less than 10 in that text field are not of any).

    So
    BanksID (autonumber) Bank
    1 CBA
    2 ANZ

    and then the tblSchools has a text field with CBA or ANZ in the record that I need to convert to a 1 or 2

  4. #4
    Ruegen's Avatar
    Ruegen is offline VIP
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jul 2013
    Location
    Australia
    Posts
    1,496
    I'm thinking of making a form of the table with some vba that loops through and updates the text in the field bankid with a corresponding number using an if

    hoping that will work

  5. #5
    Ruegen's Avatar
    Ruegen is offline VIP
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jul 2013
    Location
    Australia
    Posts
    1,496
    I did this
    Private Sub Form_Load()


    With Me.Recordset
    Do Until Me.Auto = 11610
    .MoveNext
    If txtBankID = "CBA" Then
    txtBankID = "1"


    ElseIf txtBankID = "Westpac" Then
    txtBankID = "2"


    ElseIf txtBankID = "NAB" Then
    txtBankID = "3"


    ElseIf txtBankID = "Bk of SA" Then
    txtBankID = "4"


    ElseIf txtBankID = "ANZ" Then
    txtBankID = "5"


    ElseIf txtBankID = "Bendigo Bank" Then
    txtBankID = "6"


    ElseIf txtBankID = "St George" Then
    txtBankID = "7"






    End If
    Loop
    End With


    End Sub

    works

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

Similar Threads

  1. Replies: 3
    Last Post: 05-14-2013, 10:48 PM
  2. Replies: 6
    Last Post: 12-16-2012, 08:43 AM
  3. Converting text to number type
    By togo in forum Access
    Replies: 12
    Last Post: 09-18-2012, 12:59 PM
  4. Replies: 1
    Last Post: 07-12-2012, 12:09 PM
  5. Replies: 1
    Last Post: 02-04-2011, 04:58 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