How do I output result to table values

  • Thread starter Anna Peters via AccessMonster.com
  • Start date
A

Anna Peters via AccessMonster.com

The following url at is an example of url's stored in the stat_keywords
table: /index.cfm?
section_id=24&need_help_stat_id=5&geriatric_topic_id=4&sub_section_id=33&page_id=48&tab=1

I needed to split the url at the '&', see the following code:

Private Sub Command10_Click()
Dim strURL As String
Dim tempstring As String
Dim counter As Integer
Dim p As Integer
Dim i As Integer

counter = 0

strURL = "index.cfm?
section_id=24&geriatric_topic_id=4&sub_section_id=34&page_id=49&tab=2"

For p = 1 To Len(strURL)

tempstring = Mid(strURL, p, 1)

If tempstring = "&" Then counter = counter + 1

Next p

For i = 1 To counter

tempstring = Split(strURL, "&")(i)

MsgBox tempstring

Next i

End Sub


I now need the split values to be stored into the fields in the
stat_keywords table, here are the fields section_id, need_help_stat_id,
geriatric_topic_id, sub_section_id, and page_id.
 
G

Guest

The first problem is the way you are using the Split function. It does not
return a string, it returns an array. If you code:
strURL =
"index.cfm?section_id=24&geriatric_topic_id=4&sub_section_id=34&page_id=49&tab=2"
fldValues = SPLIT(strURL)
For intX = 0 to Ubound(fldValues)
fldValues(intX) = right(fldValues(intX),len(fldValues(intX)) -
instr(fldValues(intX),"="))
Next intX
Now each row of fldValues contains the value to put in your fields:
fldValue(0) = "24"
fldValue(1) = "48"
fldValue(2) = "34"
fldValue(3) = "49"
fldValue(4) = "2"
Note they are all stings

Now, we can assign the values to the fields (assuming they are in the same
order as in the URL)

Sub AssignValues()
Dim rst As Recordset
Dim fld As Field
Dim intX As Integer
strURL =
"index.cfm?section_id=24&geriatric_topic_id=4&sub_section_id=34&page_id=49&tab=2"
fldValues = SPLIT(strURL)
For intX = 0 to Ubound(fldValues)
fldValues(intX) = right(fldValues(intX),len(fldValues(intX)) -
instr(fldValues(intX),"="))
Next intX
Set rst = CurrentDb.OpenRecordset("MyTableName")
intX=0
With rst
For Each fld In rst.Fields
fld.Name = fldValues(intX)
intX = intX + 1
Next
End With
rst.Update
rst.Close
Set rst = Nothing
End Sub

If the field data types are not string, you may have to convert the strings
in fldValues to the correct data type.
 
A

Anna Peters via AccessMonster.com

I need to pull the data from a field in a table. I used that block of text
as a test. How do I add a field from the table.

Thanks for your help.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top