Results 1 to 3 of 3

Thread: VBA script not writing to field as expected
Thanks Thanks: 0 Likes Likes: 0

  1. #1
    Board Regular
    Join Date
    May 2011
    Location
    Raleigh, NC
    Posts
    698
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default VBA script not writing to field as expected

    I am using the VBA below to try to update the FirstName, LastName and MiddleName to a table. Everything seems to be working except when I try to write the string values to the record set.

    Any ideas why this is not working?



    Code:
    Option Compare Database
    
    Private Sub parseNames()
    Dim dbs
    Dim qdf
    Dim rst
    Dim firstName as String
    Dim lastName as String
    Dim midName as String
    
    
    Set db = CurrentDb()
    Set qdf = db.QueryDefs("NameParse")
    Set rst = qdf.OpenRecordset()
    
    
    If Not (rst.EOF And rst.BOF) Then
    
    
        rst.MoveFirst
        Do Until rst.EOF = True
            rst.Edit
            emailName = rst("Email Name")
    
    
                If emailName <> "" Then
            'here I am doing some work to parse out first, last and middle names from email addresses
       
                End If
                firstName = Trim(firstName)
                lastName = Trim(lastName)
                midName = Trim(midName)
    
    
                rst.FirstName.Value = firstName
                rst.LastName.Value = lastName
                rst.MiddleName.Value = midName
            rst.MoveNext
        Loop
        
    End If
    
    
    End Sub
    60% of the time it works every time.

  2. #2
    Board Regular Norie's Avatar
    Join Date
    Apr 2004
    Location
    Stirling, Scotland
    Posts
    75,157
    Post Thanks / Like
    Mentioned
    62 Post(s)
    Tagged
    6 Thread(s)

    Default Re: VBA script not writing to field as expected

    Try adding this before you move to the next record.
    Code:
    rst.Update
    If posting code please use code tags.

  3. #3
    Board Regular
    Join Date
    Jul 2010
    Posts
    450
    Post Thanks / Like
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)

    Default Re: VBA script not writing to field as expected

    Also replace:

    Code:
    rst.FirstName.Value = firstName
    with
    Code:
    rst!FirstName = firstName
    Last edited by stumac; May 10th, 2019 at 04:46 AM.

Some videos you may like

User Tag List

Tags for this Thread

Like this thread? Share it with others

Like this thread? Share it with others

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •