Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Cant' generalize code to use with different forms

Status
Not open for further replies.

Grandkathy

Technical User
Jan 13, 2005
32
0
0
US
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!
 
And the Screen.ActiveControl ?

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
Asking about generalizing the code w/o providing the function declaration:
Code:
[Private | Public], [Sub | Function] [i]ProcedureName[/i] (ArgList)

seems a bit far to the left of reality -at least for me.

Gnerally, speaking, there are numerous examples within these fora, and a variety of approaches to the transference of the information between the ojects. Some prefer to pass hte name(s) of the objects to the procedures and 'find' the coresponding object(s) (these use strings in hte ArgList for the obj names). Others simply pass the information as object types [Form | Control] and use the obj reference to traverse the object hierarchy (note: passing a CONTROL object implicitly identifies the FORM via the parent property of the control - but this CAN be a tedious process if the control is is several layers deep into subforms, tab controls etc.)

Please make at least a token attempt to use search in thse fora (and other sites - if desired) using some simple yet relevant phrases, like (as control or as form).




MichaelRed


 
Try this:
Code:
Dim CurrentForm As Form
Set CurrentForm = Screen.ActiveForm

If IsNumeric(CurrentForm![VideoID}) Then
  'etc...etc..
End If

VBSlammer
redinvader3walking.gif

"You just have to know which screws to turn." - Professor Bob
 
Oops, small typo:
Code:
If IsNumeric(CurrentForm![VideoID[red]][/red]) Then


VBSlammer
redinvader3walking.gif

"You just have to know which screws to turn." - Professor Bob
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top