twilightsilhouette
Programmer
I have a button on form1 to open another form. Upon clicking the button, depending on information in the form1, it will either open form2 or form3. Open opening either form it filters to match specific form1 fields- if no matches it needs to create a new record with those fields pre-filled in. I know how to do this for each criteria but was hoping to create a function so I don't have to type it over and over. I can't figure out how to say "Forms!#variablestring#!ID"
For example:
Private Sub cmdOpenSpecificForms_Click()
dim stLinkCriteria as string
dim stID as string
dim stDate as string
stLinkCriteria = "[ID]=" & Me![ID] & "And" & "[Date]=" & "#"
stID = Me!ID
stDate = Me!Date
'then i go into an if for each field called 'classification'
If Me![Classification] = "Avulsion" Then
'this is the filter
DoCmd.OpenForm "AVULSION", , , stLinkCriteria [blue]'
Forms!Avulsion.SetFocus
'this creates the new record if no records matched in the inital filter
If IsNull(Forms!Avulsion!PatientID) Or IsNull(Forms!Avulsion!Date) Then
DoCmd.GoToRecord , , acNewRec
Forms!Avulsion!PatientID = stPatientID
Forms!Avulsion!Date = stDate
Forms!Avulsion![Tooth#] = stTooth
End If[/blue]
Else
If Me![Classification] = "Intrusion" Then
DoCmd.OpenForm "INTRUSION", , , stLinkCriteria
[Blue]Forms!INTRUSION.SetFocus
If IsNull(Forms!INTRUSION!PatientID) Or IsNull(Forms!INTRUSION!Date) Then
DoCmd.GoToRecord , , acNewRec
Forms!INTRUSION!ID = stId
Forms!INTRUSION!Date = stDate
End If[/blue]
etc etc etc
End Sub
Notice the blue parts are so similar. I tried to create stFormName as string, then under each if set it to the proper form name then create a function that uses it. My problem is
Forms!stFormName!ID = stID thinks stFormName is the actual form name. How can I pass a variable to Forms!____!ID in another function???
[blue]Function checkToOpenNewRec()
Forms!____.SetFocus
If IsNull(Forms!____!ID) Or IsNull(stFoForms!____!Date) Then
DoCmd.GoToRecord , , acNewRec
Forms!____!PatientID = stPatientId
Forms!____!Date = stDate
End If
Exit Function[/blue]
For example:
Private Sub cmdOpenSpecificForms_Click()
dim stLinkCriteria as string
dim stID as string
dim stDate as string
stLinkCriteria = "[ID]=" & Me![ID] & "And" & "[Date]=" & "#"
stID = Me!ID
stDate = Me!Date
'then i go into an if for each field called 'classification'
If Me![Classification] = "Avulsion" Then
'this is the filter
DoCmd.OpenForm "AVULSION", , , stLinkCriteria [blue]'
Forms!Avulsion.SetFocus
'this creates the new record if no records matched in the inital filter
If IsNull(Forms!Avulsion!PatientID) Or IsNull(Forms!Avulsion!Date) Then
DoCmd.GoToRecord , , acNewRec
Forms!Avulsion!PatientID = stPatientID
Forms!Avulsion!Date = stDate
Forms!Avulsion![Tooth#] = stTooth
End If[/blue]
Else
If Me![Classification] = "Intrusion" Then
DoCmd.OpenForm "INTRUSION", , , stLinkCriteria
[Blue]Forms!INTRUSION.SetFocus
If IsNull(Forms!INTRUSION!PatientID) Or IsNull(Forms!INTRUSION!Date) Then
DoCmd.GoToRecord , , acNewRec
Forms!INTRUSION!ID = stId
Forms!INTRUSION!Date = stDate
End If[/blue]
etc etc etc
End Sub
Notice the blue parts are so similar. I tried to create stFormName as string, then under each if set it to the proper form name then create a function that uses it. My problem is
Forms!stFormName!ID = stID thinks stFormName is the actual form name. How can I pass a variable to Forms!____!ID in another function???
[blue]Function checkToOpenNewRec()
Forms!____.SetFocus
If IsNull(Forms!____!ID) Or IsNull(stFoForms!____!Date) Then
DoCmd.GoToRecord , , acNewRec
Forms!____!PatientID = stPatientId
Forms!____!Date = stDate
End If
Exit Function[/blue]