Solved Import flower show class numbers into Entry table imultivalue field (1 Viewer)

hedwig

New member
Local time
Today, 09:38
Joined
Jul 21, 2022
Messages
9
I am inexperienced with VBA, mainly pasting code. I realise problems with multivalue fields and am stuck. Code worked previously

'Loop Through A Table With A Multi-Value Field and Insert Values Into the Multi-Value Field From a Parsed Regular Text Field.

'ENTRY is the table and holds both string to be converted and multi-valued field (both short text fields)

'CLASSNUMBER is the multivalue field

'STRINGFIELD is the field with string of the combined, comma-separated values

Option Compare Database
Option Explicit
Option Base 1
Dim strInputString As String
Dim intNumberOfArrayEntries As Integer
Dim strStateArray(50) As String


Public Function InsertIntoMultiField()

Dim db As DAO.Database

' ************************************************** *********************
' Main recordset containing both a multi-value field and string field
' ************************************************** *********************
Dim rsENTRY As DAO.Recordset2
' ************************************************** *********************
' Now Define the Multi-Value Fields as a RecordSet
' ************************************************** *********************
Dim rsCLASSNUMBER As DAO.Recordset2

' ************************************************** *********************
' The Values of the Field Are Contained in a Field Object
' Dim fldCLASSNUMBERTemp As DAO.Field2
' ************************************************** *********************
Dim fldCLASSNUMBER As DAO.Field2
Dim I As Integer

' ************************************************** *********************
' Open the Parent File
' ************************************************** *********************
Set db = CurrentDb()

Set rsENTRY = db.OpenRecordset("ENTRY")

' ************************************************** *********************
' Set The Multi-Value Field
' ************************************************** *********************
Set fldCLASSNUMBER = rsENTRY("CLASSNUMBER")

' ************************************************** *********************
' Check to Make Sure it is Multi-Value
' ************************************************** *********************
If Not (fldCLASSNUMBER.IsComplex) Then
MsgBox ("Not A Multi-Value Field")
rsENTRY.Close
Set rsENTRY = Nothing
Set fldCLASSNUMBER = Nothing
Exit Function
Else
'MsgBox ("Selected field IS a multi-value field")
End If

On Error Resume Next
' ************************************************** *********************
' Loop Through
' ************************************************** *********************
Do While Not rsENTRY.EOF

' ************************************************** *********************
' Parse Regular Text Field into Array For Insertion into Multi-Value
' ************************************************** *********************
strInputString = rsENTRY!Stringfield
Call ParseInputString

' ************************************************** *********************
' If Entries Are Present, Add Them To The Multi-Value Field
' ************************************************** *********************
If intNumberOfArrayEntries > 0 Then
Set rsCLASSNUMBER = fldCLASSNUMBER.Value
rsENTRY.Edit
For I = 1 To intNumberOfArrayEntries
rsCLASSNUMBER.AddNew
rsCLASSNUMBER("Value") = strStateArray(I)
rsCLASSNUMBER.Update
Next I
rsCLASSNUMBER.Close
rsENTRY.Update
End If
rsENTRY.MoveNext
Loop

On Error GoTo 0

rsENTRY.Close
Set rsENTRY = Nothing
Set rsCLASSNUMBER = Nothing
End Function

Public Function ParseInputString()
Dim intLength As Integer
Dim intStartSearch As Integer
Dim intNextComma As Integer
Dim intStartOfItem As Integer
Dim intLengthOfItem As Integer
Dim strComma As String

strComma = ","
intNumberOfArrayEntries = 0
strInputString = Trim(strInputString)
intLength = Len(strInputString)

' ************************************************** *********************
' Skip Zero Length Strings
' ************************************************** *********************
If intLength = 0 Then
Exit Function
End If

' ************************************************** *********************
' Strip Any Leading Comma
' ************************************************** *********************
If Mid(strInputString, 1, 1) = "," Then
Mid(strInputString, 1, 1) = " "
strInputString = Trim(strInputString)
intLength = Len(strInputString)
If intLength = 0 Then
Exit Function
End If
End If

' ************************************************** *********************
' Strip Any Trailing Comma
' ************************************************** *********************
If Mid(strInputString, intLength, 1) = "," Then
Mid(strInputString, intLength, 1) = " "
strInputString = Trim(strInputString)
intLength = Len(strInputString)
If intLength = 0 Then
Exit Function
End If
End If

intStartSearch = 1
' ************************************************** *********************
' Loop Through And Parse All the Items
' ************************************************** *********************
Do
intNextComma = InStr(intStartSearch, strInputString, strComma)
If intNextComma <> 0 Then
intNumberOfArrayEntries = intNumberOfArrayEntries + 1
intStartOfItem = intStartSearch
intLengthOfItem = intNextComma - intStartOfItem
strStateArray(intNumberOfArrayEntries) = Trim(Mid(strInputString, intStartOfItem, intLengthOfItem))
intStartSearch = intNextComma + 1
Else
intNumberOfArrayEntries = intNumberOfArrayEntries + 1
intStartOfItem = intStartSearch
intLengthOfItem = intLength - intStartSearch + 1
strStateArray(intNumberOfArrayEntries) = Trim(Mid(strInputString, intStartOfItem, intLengthOfItem))
End If

Loop Until intNextComma = 0

End Function

Data mismatch error on line 66 Set fldCLASSNUMBER = rsENTRY("CLASSNUMBER")
 

Uncle Gizmo

Nifty Access Guy
Staff member
Local time
Today, 09:38
Joined
Jul 9, 2003
Messages
16,271
Please repost your code use code tags to preserve formatting. Very difficult to read as presented.

To use code tags, paste your code, highlight it then click the </> button

(These instructions copied from a @CJ_London post)
 

jdraw

Super Moderator
Staff member
Local time
Today, 04:38
Joined
Jan 23, 2006
Messages
15,379
I agree with Uncle Gizmo and would suggest that you post a copy of the database (zip format).
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 16:38
Joined
May 7, 2009
Messages
19,232
take ENTRY table and put in Design view.
did you see CLASSNUMBER field there?
 

hedwig

New member
Local time
Today, 09:38
Joined
Jul 21, 2022
Messages
9
I agree with Uncle Gizmo and would suggest that you post a copy of the database (zip format).
Unable to attach zip or RAR file therefore attaching copy of database
 

bastanu

AWF VIP
Local time
Today, 01:38
Joined
Apr 13, 2010
Messages
1,402
Cross-posted with activity here:
 

hedwig

New member
Local time
Today, 09:38
Joined
Jul 21, 2022
Messages
9
i did recreate your "table" and your sub, they work fine, no error.
Thank you for your trouble.
Well. It did work previously. But not working now hence upset! Any suggestions?
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 16:38
Joined
May 7, 2009
Messages
19,232
you may try to change the code, from:

Set fldCLASSNUMBER = rsENTRY("CLASSNUMBER")

To:

Set fldCLASSNUMBER = rsENTRY.Fields("CLASSNUMBER")
 

hedwig

New member
Local time
Today, 09:38
Joined
Jul 21, 2022
Messages
9
Unable to send zip or RAR file so sent database
 

Attachments

  • GFS ver11 2022 SHOW.accdb
    4 MB · Views: 86

hedwig

New member
Local time
Today, 09:38
Joined
Jul 21, 2022
Messages
9
I have ms access 10 .version 2206. tried changing field2 as suggested but no difference
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 16:38
Joined
May 7, 2009
Messages
19,232
what if you declare it as variant:

Dim fldCLASSNUMBER
 

hedwig

New member
Local time
Today, 09:38
Joined
Jul 21, 2022
Messages
9
thank you all for your patience and tuition
Soved as bug in updated version 2206 Access – Bug – .Fields Not Working Anymore | DEVelopers HUT (devhut.net).
At present using msaccess 2010 and evrything works
 

Users who are viewing this thread

Top Bottom