Command Button problems

  • Thread starter Anna Peters via AccessMonster.com
  • Start date
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
 
D

Douglas J. Steele

What exactly does "doesn't work" mean? Are you getting an error? If so,
what's the error? Or is absolutely nothing happening? (If, for instance, you
were to put a message box inside your Code (A) sample, it doesn't fire,
indicating that the code isn't being executed.)

If the latter, a common problem is that the control hasn't been properly
linked to the code. Take a look at the properties for cmdSplit. Beside the
On Click entry, does it have [Event Procedure]?
 

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

Similar Threads


Top