dmt32
Thank you for your reply. Below is the code I am using which is based on similarly structured code I have used many times before. It is of syntax that I can understand.
The only sub-routine which is failing is the cmdViewRecord_Click() when I receive the message box "Race Time Not Found"
If you can see any changes which might assist this would be helpful, I shall be applying the code you provided shortly.
Meanwhile, please could you advise from yur reply where the following should be added and the source of "Cells(1,10).Text" as I am trying to understand why these numbers are significant. Many thanks
Current Code
Notes In Italics
Problem Code In Bold
Dim Currentrow As Long
Private Sub FullDetails_Click()
End Sub
Private Sub UserForm_Initialize()
txtBetCode = ""
txtMeetingVenue = ""
txtRaceTime = ""
txtNumberOfRunners = ""
txtFavouriteOddsF = ""
txtFavouriteOddsD = ""
cboEachWayOdds = ""
txtNumberOfPlaces = ""
txtSelectionNumber = ""
txtSelectionName = ""
txtBettingPlace1 = ""
txtBettingPrice1F = ""
txtBettingPrice1D = ""
txtSelectionGroup = ""
txtBettingPlace2 = ""
txtBettingPrice2F = ""
txtBettingPrice2D = ""
cboBetGroup = ""
boBetStake = ""
boBetType = ""
cboPriceOption = ""
txtStartingPrice = ""
cboRaceResult = ""
txtStartingPriceF = ""
txtStartingPriceD = ""
txtRule4Deduction = ""
cboDeadHeat = ""
txtNonRunnerBeforeBet = ""
txtNonRunnerAfterBet = ""
txtMeetingVenue.SetFocus
End Sub
Private Sub txtMeetingVenue_Change()
With Me.ActiveControl
.Value = StrConv(.Value, vbProperCase)
End With
End Sub
Private Sub txtSelectionName_Change()
With Me.ActiveControl
.Value = StrConv(.Value, vbProperCase)
End With
End Sub
Private Sub txtRaceTime_Afterupdate()
'Converts the keyed information into "hh:mm" format
Dim tString As String
With txtRaceTime
'Check if user put in a colon or not
If InStr(1, .Value, ":", vbTextCompare) = 0 Then
'If not, make string 4 digits and insert colon
tString = Format(.Value, "0000")
tString = Left(tString, 2) & ":" & Right(tString, 2)
txtRaceTime.Value = Format(TimeValue(tString), "hh:mm")
Else
'Otherwise, take value as given
.Value = Format(.Value, "hh:mm")
End If
End With
End Sub
Private Sub cmdAddRecord_Click()
Worksheets("Selections").Activate
lastrow = ActiveSheet.Cells(Rows.Count, 2).End(xlUp).Row
ActiveSheet.Cells(lastrow + 1, 2).Value = txtMeetingVenue.Value
ActiveSheet.Cells(lastrow + 1, 3).Value = txtRaceTime.Value
ActiveSheet.Cells(lastrow + 1, 4).Value = txtNumberOfRunners.Value
End Sub
Private Sub cmdViewRecord_Click()
'Used to search for a unique Race Time in the database and return all corresponding values to the user form
'This Search function should be used ONLY when updating or viewing full records
Worksheets("Selections").Activate
Dim Res As Variant
Dim lastrow
Dim myFind As String
Res = Application.Match(txtRaceTime, Sheets("Selections").Range("C2:C70"), 0)
If IsError(Res) Then
MsgBox "Race Time Not Found", vbInformation, "Race Time Not Found"
Call UserForm_Initialize
txtRaceTime.SetFocus
Exit Sub
End If
lastrow = Sheets("Selections").Range("C" & Rows.Count).End(xlUp).Row
myFind = txtRaceTime
For Currentrow = 2 To lastrow
If Cells(Currentrow, 2).Text = myFind Then
txtBetCode.Value = ActiveSheet.Cells(Currentrow, 1).Value
txtMeetingVenue.Value = ActiveSheet.Cells(Currentrow, 2).Value
txtRaceTime.Value = ActiveSheet.Cells(Currentrow, 3).Value
txtNumberOfRunners.Value = ActiveSheet.Cells(Currentrow, 4).Value
txtFavouriteOddsF.Value = ActiveSheet.Cells(Currentrow, 5).Value
txtFavouriteOddsD.Value = ActiveSheet.Cells(Currentrow, 6).Value
cboEachWayOdds.Value = ActiveSheet.Cells(Currentrow, 7).Value
txtNumberOfPlaces.Value = ActiveSheet.Cells(Currentrow, 8).Value
txtSelectionNumber.Value = ActiveSheet.Cells(Currentrow, 9).Value
txtSelectionName.Value = ActiveSheet.Cells(Currentrow, 10).Value
txtBettingPlace1.Value = ActiveSheet.Cells(Currentrow, 11).Value
txtBettingPrice1F.Value = ActiveSheet.Cells(Currentrow, 12).Value
txtBettingPrice1D.Value = ActiveSheet.Cells(Currentrow, 13).Value
txtSelectionGroup.Value = ActiveSheet.Cells(Currentrow, 14).Value
txtBettingPlace2.Value = ActiveSheet.Cells(Currentrow, 15).Value
txtBettingPrice2F.Value = ActiveSheet.Cells(Currentrow, 16).Value
txtBettingPrice2D.Value = ActiveSheet.Cells(Currentrow, 17).Value
cboBetGroup.Value = ActiveSheet.Cells(Currentrow, 18).Value
cboBetStake.Value = ActiveSheet.Cells(Currentrow, 19).Value
cboBetType.Value = ActiveSheet.Cells(Currentrow, 20).Value
cboPriceOption.Value = ActiveSheet.Cells(Currentrow, 21).Value
txtPriceTakenSP.Value = ActiveSheet.Cells(Currentrow, 22).Value
cboSelectionResult.Value = ActiveSheet.Cells(Currentrow, 23).Value
txtPriceTakenSPF.Value = ActiveSheet.Cells(Currentrow, 24).Value
txtPriceTakenSPD.Value = ActiveSheet.Cells(Currentrow, 25).Value
txtRule4Deduction.Value = ActiveSheet.Cells(Currentrow, 26).Value
cboDeadHeat.Value = ActiveSheet.Cells(Currentrow, 27).Value
txtNonRunnersBeforeBet.Value = ActiveSheet.Cells(Currentrow, 28).Value
txtNonRunnersAfterBet.Value = ActiveSheet.Cells(Currentrow, 29).Value
Exit For
End If
Next Currentrow
txtRaceTime.SetFocus
End Sub
Private Sub cmdUpdateRecord_Click()
'Used to update existing records
Worksheets("Selections").Activate
answer = MsgBox("Update the Record?", vbYesNo + vbQuestion, "Update Record?")
If answer = vbNo Then
Call UserForm_Initialize
txtRaceTime.SetFocus
Else
'ActiveSheet.Cells(Currentrow, 1).Value = txtBetCode.Value
ActiveSheet.Cells(Currentrow, 2).Value = txtMeetingVenue.Value
ActiveSheet.Cells(Currentrow, 3).Value = txtRaceTime.Value
ActiveSheet.Cells(Currentrow, 4).Value = txtNumberOfRunners.Value
ActiveSheet.Cells(Currentrow, 5).Value = txtFavouriteOddsF.Value
'ActiveSheet.Cells(Currentrow, 6).Value = txtFavouriteOddsD.Value
ActiveSheet.Cells(Currentrow, 7).Value = cboEachWayOdds.Value
ActiveSheet.Cells(Currentrow, 8).Value = txtNumberOfPlaces.Value
ActiveSheet.Cells(Currentrow, 9).Value = txtSelectionNumber.Value
ActiveSheet.Cells(Currentrow, 10).Value = txtSelectionName.Value
ActiveSheet.Cells(Currentrow, 11).Value = txtBettingPlace1.Value
ActiveSheet.Cells(Currentrow, 12).Value = txtBettingPrice1F.Value
'ActiveSheet.Cells(Currentrow, 13).Value = txtBettingPrice1D.Value
ActiveSheet.Cells(Currentrow, 14).Value = txtSelectionGroup.Value
ActiveSheet.Cells(Currentrow, 15).Value = txtBettingPlace2.Value
ActiveSheet.Cells(Currentrow, 16).Value = txtBettingPrice2F.Value
'ActiveSheet.Cells(Currentrow, 17).Value = txtBettingPrice2D.Value
ActiveSheet.Cells(Currentrow, 18).Value = cboBetGroup.Value
ActiveSheet.Cells(Currentrow, 19).Value = cboBetStake.Value
ActiveSheet.Cells(Currentrow, 20).Value = cboBetType.Value
ActiveSheet.Cells(Currentrow, 21).Value = cboPriceOption.Value
ActiveSheet.Cells(Currentrow, 22).Value = txtPriceTakenSP.Value
ActiveSheet.Cells(Currentrow, 23).Value = cboSelectionResult.Value
'ActiveSheet.Cells(Currentrow, 24).Value = txtPriceTakenSPF.Value
'ActiveSheet.Cells(Currentrow, 25).Value = txtPriceTakenSPD.Value
ActiveSheet.Cells(Currentrow, 26).Value = txtRule4Deduction.Value
ActiveSheet.Cells(Currentrow, 27).Value = cboDeadHeat.Value
ActiveSheet.Cells(Currentrow, 28).Value = txtNonRunnersBeforeBet.Value
ActiveSheet.Cells(Currentrow, 29).Value = txtNonRunnersAfterBet.Value
MsgBox "Record has been updated", 0, "Record Updated"
Call UserForm_Initialize
txtRaceTime.SetFocus
End If
End Sub
Private Sub cmdClearForm_Click()
Call UserForm_Initialize
End Sub
Private Sub cmdCloseForm_Click()
Unload Me
End Sub