I first tried another method but it was not working.
Now I get this code only to work with the first part of the "If then" code. The 2nd and 3rd "if then" does not want to fire, and populate data to subform.
See screen pic.
The main form is called "frmrtMainc hip"
subform = RaceTimingSF3ch ip
Racenumbers are sometimes received in the strInput txtfield from RFID chips in this format - 0001000,0002000 ,0003000, and i then have to split it before populating it to the subform "Racenumber " field.
I do it successfully into "data1", "data2","da ta3" on the mainform.
My problem however, is to copy the Data 1-3 fields to "Racenumber " field in the subform "RaceTimingSF3c hip" after a new line has been added everytime. Only Data1 seems to work.
here is current code:
If i knew how, i would preferred to copy the the first 5 digits received (0001000) of a string (ie 0001000,0002000 ,0003000,) in the strInput field on mainform directly to the subform "Racenumber " field,followed by the next 5 then then next 5 etc
Now i have to split it first to secondary fields(data1,da ta2,data3) and then try and copy it to the subform.
Any suggestions please?
The module code i used for the above splitting if anybody is interested is:
[imgnothumb]http://bytes.com/attachments/attachment/5745d1322939281/copy1.jpg[/imgnothumb]
Now I get this code only to work with the first part of the "If then" code. The 2nd and 3rd "if then" does not want to fire, and populate data to subform.
See screen pic.
The main form is called "frmrtMainc hip"
subform = RaceTimingSF3ch ip
Racenumbers are sometimes received in the strInput txtfield from RFID chips in this format - 0001000,0002000 ,0003000, and i then have to split it before populating it to the subform "Racenumber " field.
I do it successfully into "data1", "data2","da ta3" on the mainform.
My problem however, is to copy the Data 1-3 fields to "Racenumber " field in the subform "RaceTimingSF3c hip" after a new line has been added everytime. Only Data1 seems to work.
here is current code:
Code:
Private Sub strInput_AfterUpdate()
Me.Data1 = tbExtractStr(Me.strInput, "1", ",", "")
Me.Data2 = tbExtractStr(Me.strInput, "2", ",", "")
Me.Data3 = tbExtractStr(Me.strInput, "3", ",", "")
If Data1 > 0 Then
[Forms]![frmrtmainchip]![RaceTimingSF3chip].SetFocus
DoCmd.GoToControl ("RaceNumber")
DoCmd.GoToRecord , "", acNewRec
[Forms]![frmrtmainchip]![RaceTimingSF3chip]![RaceNumber] = Me.Data1
[Forms]![frmrtmainchip]![RaceTimingSF3chip]![RaceFinishTime] = Format(Now(), "General Date")
End If
If Data2 > 0 Then
[Forms]![frmrtmainchip]![RaceTimingSF3chip].SetFocus
DoCmd.GoToControl ("RaceNumber")
DoCmd.GoToRecord , "", acNewRec
[Forms]![frmrtmainchip]![RaceTimingSF3chip]![RaceNumber] = Me.Data2
[Forms]![frmrtmainchip]![RaceTimingSF3chip]![RaceFinishTime] = Format(Now(), "General Date")
End If
If Data3 > 0 Then
[Forms]![frmrtmainchip]![RaceTimingSF3chip].SetFocus
DoCmd.GoToControl ("RaceNumber")
DoCmd.GoToRecord , "", acNewRec
[Forms]![frmrtmainchip]![RaceTimingSF3chip]![RaceNumber] = Me.Data3
[Forms]![frmrtmainchip]![RaceTimingSF3chip]![RaceFinishTime] = Format(Now(), "General Date")
End If
End Sub
If i knew how, i would preferred to copy the the first 5 digits received (0001000) of a string (ie 0001000,0002000 ,0003000,) in the strInput field on mainform directly to the subform "Racenumber " field,followed by the next 5 then then next 5 etc
Now i have to split it first to secondary fields(data1,da ta2,data3) and then try and copy it to the subform.
Any suggestions please?
The module code i used for the above splitting if anybody is interested is:
Code:
Function tbExtractStr(strIn, intNeedSegment, strDelimiter, Optional strNotFound As String) As String
' Function to chop a input string into segments and return the requested segment
' Written and developed by Thomas M. Brittell
' Copyright 1998; All rights reserved.
'
' strIn - Input string to be segmented
' intNeedSegment - Indicates the segment to be returned
' strDelimiter - The delimiter used to seperate each segment
' strNotFound - When no segment is found return the specified string if provided
'
Dim intCurrentPosition As Integer
Dim intFoundPosition As Integer
Dim intLastPosition As Integer
Dim intGetSegment As Integer
Dim wrkNotFound As String
If IsEmpty(strNotFound) Or strNotFound = "" Then
wrkNotFound = ""
Else
wrkNotFound = strNotFound
End If
intCurrentPosition = 0
intFoundPosition = 0
intLastPosition = 0
intGetSegment = intNeedSegment
Do While intGetSegment > 0
intLastPosition = intCurrentPosition
'Find a occurance of the delimiter
intFoundPosition = InStr(intCurrentPosition + 1, strIn, Left$(strDelimiter, 1))
If intFoundPosition > 0 Then
intCurrentPosition = intFoundPosition
intGetSegment = intGetSegment - 1
Else
'End of input string so exit
intCurrentPosition = Len(strIn) + 1
Exit Do
End If
Loop
'If nothing was found and you had at least one delimiter return ""
If (intFoundPosition = 0) And ((intGetSegment <> intNeedSegment) And (intGetSegment > 1)) Then
tbExtractStr = wrkNotFound
Else
'Return the segment between the last position and the current one
tbExtractStr = Mid$(strIn, intLastPosition + 1, intCurrentPosition - intLastPosition - 1)
End If
End Function
Comment