craigachan
Registered User.
- Local time
- Today, 06:00
- Joined
- Nov 9, 2007
- Messages
- 285
I'm trying to sort a string of numbers. Each number is separated by a comma and there may be spaces. Example: 4,6,2,35,26 ,24
I've written a routine to strip out the spaces, then sort the numbers by using tempTables, then reassembling the string in sorted order. So now my string is: 2,4,6,24,26,35.
My code works well but I get a screen flash when I run the code, mostly from my forms opening and closing. So I tried to hide the Forms while it runs, but then I get a runtime 2105 error: can't go to the specified record. If I unhide my forms again, it works great.
Question: Why can't I goto a record on a form that is hidden? or am I missing something else.
Question: If I can't do anything else, how can I get rid of the flashing screen from my forms opening and closign?
Here is the code:
Thanks for your help
I've written a routine to strip out the spaces, then sort the numbers by using tempTables, then reassembling the string in sorted order. So now my string is: 2,4,6,24,26,35.
My code works well but I get a screen flash when I run the code, mostly from my forms opening and closing. So I tried to hide the Forms while it runs, but then I get a runtime 2105 error: can't go to the specified record. If I unhide my forms again, it works great.
Question: Why can't I goto a record on a form that is hidden? or am I missing something else.
Question: If I can't do anything else, how can I get rid of the flashing screen from my forms opening and closign?
Here is the code:
Code:
Private Sub cmdSort_Click()
'------------Get rid of spaces
Dim cc As Integer
Dim x As Integer
Dim Rm As String
Dim StrNms As String
Dim strNew As String
Dim strRem As String ' string remaining
Dim NOfC As Integer
Dim c2c As Integer 'count to comma
cc = Len(Me.Before)
StrNms = Me.Before
strNew = ""
strRem = StrNms
For x = 1 To cc
If Left(strRem, 1) <> Chr(32) Then
strNew = strNew & Left(strRem, 1)
Else
strNew = strNew
End If
If Left(strRem, 1) = "," Then
NOfC = NOfC + 1 ' count the commas
End If
strRem = Right(StrNms, cc - x)
Next x
Me.After = strNew ' REMOVE LATER
'-------------------Put strNew in table as numbers Then Sort
DoCmd.SetWarnings False
DoCmd.OpenQuery "qryDeltempChartsortNum"
DoCmd.Close acQuery, "qrydeltempchartsortnum"
DoCmd.SetWarnings True
DoCmd.OpenForm "tempChartSortNum", acFormDS, , , acFormEdit
Dim ftemp As Form
Dim strRemHead As String
Dim strPreHead As String
Dim pc As Integer 'previous comma
Dim st As Integer 'starting point
Set ftemp = Forms!tempChartSortNum
st = 1
pc = 1
strRemHead = strNew
x = 1
For x = 1 To (NOfC + 1)
DoCmd.GoToRecord , , acGoTo, x
c2c = InStr(st, strRemHead, ",")
If c2c <> 0 Then
ftemp.Number = Mid(strRemHead, st, c2c - 1)
strRemHead = Right(strRemHead, Len(strRemHead) - c2c)
Else
ftemp.Number = strRemHead
End If
Next x
DoCmd.Close acForm, "tempChartsortNum"
DoCmd.OpenForm "tempChartsortedNum"
'-------------------Rebuild numbers in sort order
Dim RC As Integer 'Record Count
strNew = ""
RC = DCount("*", "tempChartSortNum")
For x = 1 To RC
DoCmd.GoToRecord , , acGoTo, x
If strNew = "" Then
strNew = Forms!tempChartsortedNum.Number
Else
strNew = strNew & "," & Forms!tempChartsortedNum.Number
End If
Next x
Me.Sorted = strNew
DoCmd.Close acForm, "tempchartsortednum"
End Sub
Thanks for your help