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
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