Grandkathy
Technical User
I have the following piece of code which I use to verify that a user has entered a video id accurately.
I want to be able to generalize it more and use it on more than one form, I have 3 or 4 forms which use the Video ID field.
I’ve tried using me. Instead of the form name, but it gives me an error “ invalid use of Me keyword”
strSQL = "tblVideo"
Set cnn = CurrentProject.Connection 'sets the connection to current database
Set rst = New ADODB.Recordset 'sets the recordset to a new ADODB recordset
rst.Open strSQL, cnn, adOpenStatic, adLockOptimistic, adCmdTable 'opens the recordset MAKE SURE ALL PARAMETERS ARE INCLUDED - THIS WILL NOT WORK WITHOUT THEM!!!
If IsNumeric(Forms!frmReservations.[VideoID]) Then
If Forms!frmReservations.VideoID < 1000 And Forms!frmReservations.VideoID > 99 Then
Forms!frmReservations.VideoID = "V0" & vVideoID
ElseIf Forms!frmReservations.VideoID < 100 And Forms!frmReservations.VideoID > 9 Then
Forms!v.VideoID = "V00" & Forms!frmReservations.VideoID
ElseIf Forms!frmReservations.VideoID < 10 Then
Forms!frmReservations.VideoID = "V000" & Forms!frmReservations.VideoID
Else
Forms!frmReservations.VideoID = "V" & Forms!frmReservations.VideoID
End If
VidID = Forms!frmReservations.VideoID
Else
VidID = Forms!frmReservations.VideoID
If Left(VidID, 1) <> "V" Then
DoCmd.GoToControl "VideoID"
MsgBox "Please verify the Video ID. Video ID's must start with ""V"". You can also just type the number."
Exit Function
End If
End If
And,
I’ve tried dimming a variable for the CurrentObjectName as in the following code, but I then get a message that says it can’t find “CurrentForm”.
Dim CurrentForm
CurrentForm = Application.CurrentObjectName
If IsNumeric(Forms!CurrentForm.[VideoID]) Then
If Forms!CurrentForm.VideoID < 1000 And Forms!CurrentForm.VideoID > 99 Then
Forms!CurrentForm.VideoID = "V0" & vVideoID
ElseIf Forms!CurrentForm.VideoID < 100 And Forms!CurrentForm.VideoID > 9 Then
Forms!v.VideoID = "V00" & Forms!CurrentForm.VideoID
ElseIf Forms!CurrentForm.VideoID < 10 Then
Forms!CurrentForm.VideoID = "V000" & Forms!CurrentForm.VideoID
Else
Forms!CurrentForm.VideoID = "V" & Forms!CurrentForm.VideoID
End If
VidID = Forms!CurrentForm.VideoID
Else
VidID = Forms!CurrentForm.VideoID
If Left(VidID, 1) <> "V" Then
DoCmd.GoToControl "VideoID"
MsgBox "Please verify the Video ID. Video ID's must start with ""V"". You can also just type the number."
Exit Function
End If
End If
PLEASE HELP!
I want to be able to generalize it more and use it on more than one form, I have 3 or 4 forms which use the Video ID field.
I’ve tried using me. Instead of the form name, but it gives me an error “ invalid use of Me keyword”
strSQL = "tblVideo"
Set cnn = CurrentProject.Connection 'sets the connection to current database
Set rst = New ADODB.Recordset 'sets the recordset to a new ADODB recordset
rst.Open strSQL, cnn, adOpenStatic, adLockOptimistic, adCmdTable 'opens the recordset MAKE SURE ALL PARAMETERS ARE INCLUDED - THIS WILL NOT WORK WITHOUT THEM!!!
If IsNumeric(Forms!frmReservations.[VideoID]) Then
If Forms!frmReservations.VideoID < 1000 And Forms!frmReservations.VideoID > 99 Then
Forms!frmReservations.VideoID = "V0" & vVideoID
ElseIf Forms!frmReservations.VideoID < 100 And Forms!frmReservations.VideoID > 9 Then
Forms!v.VideoID = "V00" & Forms!frmReservations.VideoID
ElseIf Forms!frmReservations.VideoID < 10 Then
Forms!frmReservations.VideoID = "V000" & Forms!frmReservations.VideoID
Else
Forms!frmReservations.VideoID = "V" & Forms!frmReservations.VideoID
End If
VidID = Forms!frmReservations.VideoID
Else
VidID = Forms!frmReservations.VideoID
If Left(VidID, 1) <> "V" Then
DoCmd.GoToControl "VideoID"
MsgBox "Please verify the Video ID. Video ID's must start with ""V"". You can also just type the number."
Exit Function
End If
End If
And,
I’ve tried dimming a variable for the CurrentObjectName as in the following code, but I then get a message that says it can’t find “CurrentForm”.
Dim CurrentForm
CurrentForm = Application.CurrentObjectName
If IsNumeric(Forms!CurrentForm.[VideoID]) Then
If Forms!CurrentForm.VideoID < 1000 And Forms!CurrentForm.VideoID > 99 Then
Forms!CurrentForm.VideoID = "V0" & vVideoID
ElseIf Forms!CurrentForm.VideoID < 100 And Forms!CurrentForm.VideoID > 9 Then
Forms!v.VideoID = "V00" & Forms!CurrentForm.VideoID
ElseIf Forms!CurrentForm.VideoID < 10 Then
Forms!CurrentForm.VideoID = "V000" & Forms!CurrentForm.VideoID
Else
Forms!CurrentForm.VideoID = "V" & Forms!CurrentForm.VideoID
End If
VidID = Forms!CurrentForm.VideoID
Else
VidID = Forms!CurrentForm.VideoID
If Left(VidID, 1) <> "V" Then
DoCmd.GoToControl "VideoID"
MsgBox "Please verify the Video ID. Video ID's must start with ""V"". You can also just type the number."
Exit Function
End If
End If
PLEASE HELP!