A
Anna Peters via AccessMonster.com
I have the following code designed to split URLs stored in a table. The
code (A) is supposed to be triggered by a command button on a form but when
I click the form the code that supposed to trigger (B) doesn't work.
Nothing happens. Can I get some help trying to figure out what wrong.
Thanks in advance.
Code (A)
Private Sub cmdSplit_Click()
Dim db As DAO.Database, rst As DAO.Recordset
Set db = CurrentDb
Set rst = db.OpenRecordset("tblURLs")
With rst
..MoveFirst
Do While Not .EOF
fBreakURL (rst!UrlIn)
rst.Edit
rst!SectionIn = typData.SectionID
rst!NeedHelpStatIn = typData.NeedHelpStatID
rst!SubSectionIn = typData.SubSectionID
rst!GeriatricIn = typData.GeriatricID
rst!PageIn = typData.PageID
rst!TabIn = typData.TabID
rst.Update
..MoveNext
Loop
End With
Code (B)
Option Compare Database
Option Explicit
Type typeURL
SectionID As Long
NeedHelpStatID As Long
GeriatricID As Long
SubSectionID As Long
PageID As Long
TabID As Long
End Type
Public typData As typeURL
'call function using 'fBreakURL("index.cfm?
section_id=24&geriatric_topic_id=4&sub_section_id=34&page_id=49&tab=2")
'Where you can replace the string with a field name
'or controlname in your code
Function fBreakURL(strIn As String)
Dim intAt As Integer, strC As String, strVal As String
typData.GeriatricID = 0
typData.NeedHelpStatID = 0
typData.PageID = 0
typData.SectionID = 0
typData.SubSectionID = 0
typData.TabID = 0
intAt = InStr(strIn, "section_id=")
If intAt > 0 Then
intAt = intAt + 11
Do
strC = Mid(strIn, intAt, 1)
If strC <> "&" And intAt < Len(strIn) + 1 Then
strVal = strVal & strC
strC = ""
intAt = intAt + 1
Else
typData.SectionID = CLng(strVal)
strC = ""
strVal = ""
Exit Do
End If
Loop
End If
intAt = InStr(strIn, "need_help_stat_id=")
If intAt > 0 Then
intAt = intAt + 19
Do
strC = Mid(strIn, intAt, 1)
If strC <> "&" And intAt < Len(strIn) + 1 Then
strVal = strVal & strC
strC = ""
intAt = intAt + 1
Else
typData.NeedHelpStatID = CLng(strVal)
strC = ""
strVal = ""
Exit Do
End If
Loop
End If
intAt = InStr(strIn, "geriatric_topic_id=")
If intAt > 0 Then
intAt = intAt + 19
Do
strC = Mid(strIn, intAt, 1)
If strC <> "&" And intAt < Len(strIn) + 1 Then
strVal = strVal & strC
strC = ""
intAt = intAt + 1
Else
typData.GeriatricID = CLng(strVal)
strC = ""
strVal = ""
Exit Do
End If
Loop
End If
intAt = InStr(strIn, "sub_section_id=")
If intAt > 0 Then
intAt = intAt + 15
Do
strC = Mid(strIn, intAt, 1)
If strC <> "&" And intAt < Len(strIn) + 1 Then
strVal = strVal & strC
strC = ""
intAt = intAt + 1
Else
typData.SubSectionID = CLng(strVal)
strC = ""
strVal = ""
Exit Do
End If
Loop
End If
intAt = InStr(strIn, "page_id=")
If intAt > 0 Then
intAt = intAt + 8
Do
strC = Mid(strIn, intAt, 1)
If strC <> "&" And intAt < Len(strIn) + 1 Then
strVal = strVal & strC
strC = ""
intAt = intAt + 1
Else
typData.PageID = CLng(strVal)
strC = ""
strVal = ""
Exit Do
End If
Loop
End If
intAt = InStr(strIn, "tab=")
If intAt > 0 Then
intAt = intAt + 4
Do
strC = Mid(strIn, intAt, 1)
If strC <> "&" And intAt < Len(strIn) + 1 Then
strVal = strVal & strC
strC = ""
intAt = intAt + 1
Else
typData.TabID = CLng(strVal)
strC = ""
strVal = ""
Exit Do
End If
Loop
End If
Debug.Print "Section: " + CStr(typData.SectionID)
Debug.Print "Stat: " + CStr(typData.NeedHelpStatID)
Debug.Print "Geriatric: " + CStr(typData.GeriatricID)
Debug.Print "Sub_Section: " + CStr(typData.SubSectionID)
Debug.Print "Page: " + CStr(typData.PageID)
Debug.Print "Tab: " + CStr(typData.TabID)
End Function
Set rst = Nothing
Set db = Nothing
End Sub
code (A) is supposed to be triggered by a command button on a form but when
I click the form the code that supposed to trigger (B) doesn't work.
Nothing happens. Can I get some help trying to figure out what wrong.
Thanks in advance.
Code (A)
Private Sub cmdSplit_Click()
Dim db As DAO.Database, rst As DAO.Recordset
Set db = CurrentDb
Set rst = db.OpenRecordset("tblURLs")
With rst
..MoveFirst
Do While Not .EOF
fBreakURL (rst!UrlIn)
rst.Edit
rst!SectionIn = typData.SectionID
rst!NeedHelpStatIn = typData.NeedHelpStatID
rst!SubSectionIn = typData.SubSectionID
rst!GeriatricIn = typData.GeriatricID
rst!PageIn = typData.PageID
rst!TabIn = typData.TabID
rst.Update
..MoveNext
Loop
End With
Code (B)
Option Compare Database
Option Explicit
Type typeURL
SectionID As Long
NeedHelpStatID As Long
GeriatricID As Long
SubSectionID As Long
PageID As Long
TabID As Long
End Type
Public typData As typeURL
'call function using 'fBreakURL("index.cfm?
section_id=24&geriatric_topic_id=4&sub_section_id=34&page_id=49&tab=2")
'Where you can replace the string with a field name
'or controlname in your code
Function fBreakURL(strIn As String)
Dim intAt As Integer, strC As String, strVal As String
typData.GeriatricID = 0
typData.NeedHelpStatID = 0
typData.PageID = 0
typData.SectionID = 0
typData.SubSectionID = 0
typData.TabID = 0
intAt = InStr(strIn, "section_id=")
If intAt > 0 Then
intAt = intAt + 11
Do
strC = Mid(strIn, intAt, 1)
If strC <> "&" And intAt < Len(strIn) + 1 Then
strVal = strVal & strC
strC = ""
intAt = intAt + 1
Else
typData.SectionID = CLng(strVal)
strC = ""
strVal = ""
Exit Do
End If
Loop
End If
intAt = InStr(strIn, "need_help_stat_id=")
If intAt > 0 Then
intAt = intAt + 19
Do
strC = Mid(strIn, intAt, 1)
If strC <> "&" And intAt < Len(strIn) + 1 Then
strVal = strVal & strC
strC = ""
intAt = intAt + 1
Else
typData.NeedHelpStatID = CLng(strVal)
strC = ""
strVal = ""
Exit Do
End If
Loop
End If
intAt = InStr(strIn, "geriatric_topic_id=")
If intAt > 0 Then
intAt = intAt + 19
Do
strC = Mid(strIn, intAt, 1)
If strC <> "&" And intAt < Len(strIn) + 1 Then
strVal = strVal & strC
strC = ""
intAt = intAt + 1
Else
typData.GeriatricID = CLng(strVal)
strC = ""
strVal = ""
Exit Do
End If
Loop
End If
intAt = InStr(strIn, "sub_section_id=")
If intAt > 0 Then
intAt = intAt + 15
Do
strC = Mid(strIn, intAt, 1)
If strC <> "&" And intAt < Len(strIn) + 1 Then
strVal = strVal & strC
strC = ""
intAt = intAt + 1
Else
typData.SubSectionID = CLng(strVal)
strC = ""
strVal = ""
Exit Do
End If
Loop
End If
intAt = InStr(strIn, "page_id=")
If intAt > 0 Then
intAt = intAt + 8
Do
strC = Mid(strIn, intAt, 1)
If strC <> "&" And intAt < Len(strIn) + 1 Then
strVal = strVal & strC
strC = ""
intAt = intAt + 1
Else
typData.PageID = CLng(strVal)
strC = ""
strVal = ""
Exit Do
End If
Loop
End If
intAt = InStr(strIn, "tab=")
If intAt > 0 Then
intAt = intAt + 4
Do
strC = Mid(strIn, intAt, 1)
If strC <> "&" And intAt < Len(strIn) + 1 Then
strVal = strVal & strC
strC = ""
intAt = intAt + 1
Else
typData.TabID = CLng(strVal)
strC = ""
strVal = ""
Exit Do
End If
Loop
End If
Debug.Print "Section: " + CStr(typData.SectionID)
Debug.Print "Stat: " + CStr(typData.NeedHelpStatID)
Debug.Print "Geriatric: " + CStr(typData.GeriatricID)
Debug.Print "Sub_Section: " + CStr(typData.SubSectionID)
Debug.Print "Page: " + CStr(typData.PageID)
Debug.Print "Tab: " + CStr(typData.TabID)
End Function
Set rst = Nothing
Set db = Nothing
End Sub