Jmoreau
01-11-2016, 04:04 PM
I'm trying to open a form to a certain record based on the value of a field in the form.
I can't figure out how to get that certain record. The field is 'mth' so I need to have the record number where me.mth.value = strmonthyear
Can anyone help with this seemingly easy task?
Below is what I have so far:
Private Sub Form_Load()
Dim strMonthNum As Integer 'Month number (1-12)
Dim strMonth As String 'Month name (January through December)
Dim strYear As Integer 'Year number (2012 etc)
Dim strMonthYear As String 'Concatenated month and year (January2012 etc)
Dim strFormName As String
Dim recordID As String
strFormName = "frmByMonth"
strMonthNum = Month(Date)
If strMonthNum = 1 Then
strMonth = "January"
ElseIf strMonthNum = 2 Then strMonth = "February"
ElseIf strMonthNum = 3 Then strMonth = "March"
ElseIf strMonthNum = 4 Then strMonth = "April"
ElseIf strMonthNum = 5 Then strMonth = "May"
ElseIf strMonthNum = 6 Then strMonth = "June"
ElseIf strMonthNum = 7 Then strMonth = "July"
ElseIf strMonthNum = 8 Then strMonth = "August"
ElseIf strMonthNum = 9 Then strMonth = "September"
ElseIf strMonthNum = 10 Then strMonth = "October"
ElseIf strMonthNum = 11 Then strMonth = "November"
ElseIf strMonthNum = 12 Then strMonth = "December"
End If
strYear = Year(Date)
strMonthYear = strMonth & strYear
recordID = Me.Mth
'strMonthNum = strMonthNum + 23 'I keep having to add 12 to this number, but don't want to use that anymore (started with February2012)
DoCmd.GoToRecord acForm, "frmByMonth", acGoTo, strMonthNum
End Sub
I can't figure out how to get that certain record. The field is 'mth' so I need to have the record number where me.mth.value = strmonthyear
Can anyone help with this seemingly easy task?
Below is what I have so far:
Private Sub Form_Load()
Dim strMonthNum As Integer 'Month number (1-12)
Dim strMonth As String 'Month name (January through December)
Dim strYear As Integer 'Year number (2012 etc)
Dim strMonthYear As String 'Concatenated month and year (January2012 etc)
Dim strFormName As String
Dim recordID As String
strFormName = "frmByMonth"
strMonthNum = Month(Date)
If strMonthNum = 1 Then
strMonth = "January"
ElseIf strMonthNum = 2 Then strMonth = "February"
ElseIf strMonthNum = 3 Then strMonth = "March"
ElseIf strMonthNum = 4 Then strMonth = "April"
ElseIf strMonthNum = 5 Then strMonth = "May"
ElseIf strMonthNum = 6 Then strMonth = "June"
ElseIf strMonthNum = 7 Then strMonth = "July"
ElseIf strMonthNum = 8 Then strMonth = "August"
ElseIf strMonthNum = 9 Then strMonth = "September"
ElseIf strMonthNum = 10 Then strMonth = "October"
ElseIf strMonthNum = 11 Then strMonth = "November"
ElseIf strMonthNum = 12 Then strMonth = "December"
End If
strYear = Year(Date)
strMonthYear = strMonth & strYear
recordID = Me.Mth
'strMonthNum = strMonthNum + 23 'I keep having to add 12 to this number, but don't want to use that anymore (started with February2012)
DoCmd.GoToRecord acForm, "frmByMonth", acGoTo, strMonthNum
End Sub