Andromeda31
Registered User.
- Local time
- Today, 11:12
- Joined
- Oct 14, 2009
- Messages
- 33
I am trying to enter a comma separated string from a textbox into a series of (up to 4) database fields in a table, I've called the field names [animal0] [animal1] [animal2] [animal3]
am using the following code which I am adapting to my need:
I think where it is going wrong is the ('" & FieldName & "') bit. I got it to successfully enter the names in a simple table where just one field is used
e.g (animal) - how would I deal with the fact that the string may be 1,2,3 or 4 values?
Any pointers to what is missing gratefully received
Obviously I will remove the msgbox and Debug.Print lines later, and put the sql into the string strSQLinsert once it works using CurrentDb.execute
cheers
am using the following code which I am adapting to my need:
Code:
Sub cmdAddstr_Click()
Dim DataString As String
ReDim Substr(0) As String
Dim SubStrCount As Integer
Dim i As Integer
Dim strSQLinsert As String
Dim FieldName As String
' Create a comma-delimited string:
DataString = Me!MySelections.Value
Debug.Print "Data String: " & DataString
' Parse the string into sub-strings:
SubStrCount = ParseString(Substr(), DataString, ",")
' Display the sub-strings:
For i = 1 To SubStrCount
'MsgBox "Sub-String " & i & ": " & Substr(i)
FieldName = "animal" & i
DoCmd.RunSQL ("INSERT INTO animals ('" & FieldName & "') values ('" & _
Substr(i) & "')")
Debug.Print "this is it: " & Substr(i) & i
Debug.Print "this is the fieldname: " & FieldName
Next
Exit Sub
End Sub
I think where it is going wrong is the ('" & FieldName & "') bit. I got it to successfully enter the names in a simple table where just one field is used
e.g (animal) - how would I deal with the fact that the string may be 1,2,3 or 4 values?
Any pointers to what is missing gratefully received
Obviously I will remove the msgbox and Debug.Print lines later, and put the sql into the string strSQLinsert once it works using CurrentDb.execute
cheers