updating and editing a table (1 Viewer)

M

macnero

Guest
Hi,

Im writing some code which takes a number from a string and displays the number in the debug window. The program moves through each record of the current database at a time. Whats the code to put the results into a new table or update the existing table. I've tried the edit and update but get errors.
my code so far is:

' Declare variables.
Function CheckValue(strTableName As String, strColumn1 As String, strColumn2 As String)
Dim MyDB As Database
Dim rset As Recordset
Dim intI As Integer
Dim i As Integer
Dim SearchString, SearchChar, MyPos, MyPosNext, FirstWord
Dim qdf As QueryDef, strSQL As String


' Assign the current database to the database
' variable.

Set MyDB = CurrentDb
Set rset = MyDB.OpenRecordset(strTableName, dbOpenDynaset)


' move to start of list to force a count
rset.MoveFirst

' Loop through each record in the table
Do While Not rset.EOF

SearchString = rset(strColumn1) ' String to search in.
SearchChar = "/" ' Search for "/".
MyPos = InStr(1, SearchString, SearchChar) ' position of first slash mark
MyPosNext = InStr(MyPos + 1, SearchString, SearchChar) ' position of second slash mark

FirstWord = Mid(SearchString, MyPos + 1, (MyPosNext - MyPos) - 1) ' depth string


rset.MoveNext ' move to next record

Debug.Print FirstWord
MsgBox strTabName & " :" & CStr(FirstWord), vbInformation, "Values"

Loop ' end of loop

End Function
 

DALeffler

Registered Perpetrator
Local time
Today, 12:21
Joined
Dec 5, 2000
Messages
263
Have you tried this?
.
.
.
MyPosNext = InStr(MyPos + 1, SearchString, SearchChar) ' position of second slash mark

FirstWord = Mid(SearchString, MyPos + 1, (MyPosNext - MyPos) - 1) ' depth string

With rset
.Edit 'write to buffer for editing the current record
!MyTableFieldtoUpdate = FirstWord 'change a field in the curent record
.update 'update the current record - no warnings!
End With


rset.MoveNext ' move to next record

Debug.Print FirstWord
MsgBox strTabName & " :" & CStr(FirstWord), vbInformation, "Values"

Loop ' end of loop

Use .AddNew in place of .Edit for appending.

HTH, (edited message formatting...)

Doug.
 
Last edited:

cogent1

Registered User.
Local time
Today, 19:21
Joined
May 20, 2002
Messages
315
Easier way...

All this seems to do is strip slash marks away from a number. You can do this with an update query, where the criterion is "\*\" and the Update To is Mid$([MyField],2,Len([MyField])-2). Or have I misunderstood?
 

Users who are viewing this thread

Top Bottom