VBA script not writing to field as expected

jscranton

Well-known Member
Joined
May 30, 2011
Messages
707
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)


[B]            rst.FirstName.Value = firstName[/B]
[B]            rst.LastName.Value = lastName[/B]
[B]            rst.MiddleName.Value = midName[/B]
        rst.MoveNext
    Loop
    
End If


End Sub
 

Some videos you may like

Excel Facts

What do {} around a formula in the formula bar mean?
{Formula} means the formula was entered using Ctrl+Shift+Enter signifying an old-style array formula.

Norie

Well-known Member
Joined
Apr 28, 2004
Messages
75,559
Office Version
365
Platform
Windows
Try adding this before you move to the next record.
Code:
rst.Update
 

stumac

Active Member
Joined
Jul 16, 2010
Messages
471
Also replace:

Code:
rst[COLOR=#ff0000].[/COLOR]FirstName.Value = firstName
with
Code:
[B]rst[COLOR=#0000ff]![/COLOR]FirstName = firstName[/B]
 
Last edited:

Watch MrExcel Video

Forum statistics

Threads
1,099,130
Messages
5,466,852
Members
406,505
Latest member
jvdm

This Week's Hot Topics

Top