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

Quick Sum
Select a range of cells. The total appears in bottom right of Excel screen. Right-click total to add Max, Min, Count, Average.

Norie

Well-known Member
Joined
Apr 28, 2004
Messages
75,541
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,095,700
Messages
5,446,016
Members
405,377
Latest member
joaofigu78

This Week's Hot Topics

Top