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 Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Missing textbox in subform 1

Status
Not open for further replies.

pharcyder

Programmer
Mar 12, 2002
66
DE
Hi,

i've got a Form with a subform. The mainform has a textbox in it which gets its value from a textbox in the subform (i.e. [Forms]![mainform]![subform]![subformfield]).

Now the problem is, when the subform has no data in it, there is no such field and the target textbox produces an "#Error" (because there is no reference to the now mising field in the subform)

How can i prevent this textbox (in the mainform) to try to get data from the subform-textbox if it is not there (because there are no records in it) ?
Is there even a way I can check this in one line (so I don't need much code, just enter it in the textbox's content) ?

Thanks in advance,
Jens
 
Try something like this

Code:
Private Sub Form_Open(Cancel As Integer)
 
  If isnull (me.subformtextbox) Then
    me.mainformtextbox = " "
  End If


End Sub

The
Code:
Form_Open(Cancel As Integer)
could change depending on what is happening to put data in the subform textbox. If you need to only check this when the form is opened then use as is. If you want to check after something else happens or before something happens then it will change based on that.

i.e Private Sub NameofTxtBox_AfterUpdate()
 
First off, the reference to the subform should be
forms!NameOfMainForm!NameOfControlThatHoldsSubform.form!NameOfControlOnSubform

Next, if it's just that there's no data in the field, you could wrap the above in nz(). If it's that the form is not being displayed, I would say you'll have to write a function that test for the existence of the form. Something like this:

Function getTheName()
On Error GoTo error

getTheName = [Forms]![frmBank]![frmAccount].[Form]![txtAccountName]

Exit Function

error:
Select Case err.Number
Case 2424 'can't find a form or control
getTheName = Null
Resume Next
End Select
End Function

Jeremy =============
Jeremy Wallace
Designing, Developing, and Deploying Access Databases Since 1995

Take a look at the Developer's section of the site for some helpful fundamentals.
 
Thanks, Jeremy !

As I stated above the problem occurs when changing to records where the subform has no data in it (and thus no controls are showing).

I just changed the function so I can pass the control's name and use it for more than one control:
[tt]
Public Function fct_checkform(ctrlname As Object)
On Error GoTo error

fct_checkform = ctrlname
Exit Function

error:
Select Case Err.Number
Case 2424 'Kein Control oder Formular gefunden
fct_checkform = Null
Resume Next
End Select

End Function
[/tt]


Many thanks from Germany,
Jens
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top