Run-Time Error '94' Invalid use of Null

R

Richard

Hi all,

I use the below code to print Dymo labels, the purpose is to print the
number of labels in the textbox TotalParcels.The code works fine on exsting
records. When I attempt to print a new record I get Run-Time Error '94'
Invalid use of Null The code highlights on this line >> For L = 1 To
Forms!frmScan!ScanSub.Form.Parcels

When I hover the mouse over the L it = 0
Thank you
Richar
------------------------------------------------------------------------------------------------
Private Sub Label5_Click()
Dim strWhere As String
Dim L As Long

If Me.Dirty Then
Me.Dirty = False
End If


If Me.NewRecord Then
MsgBox "Select a record to print"
Else
strWhere = "[ScanID] = " & Me.[ScanID]
End If


For L = 1 To Forms!frmScan!ScanSub.Form.Parcels
DoCmd.OpenReport "rptScanlogDymo", acViewNormal, , strWhere
Next L


DoCmd.GoToRecord , , acNewRec
Department.SetFocus

End Sub
 
J

John W. Vinson

Hi all,

I use the below code to print Dymo labels, the purpose is to print the
number of labels in the textbox TotalParcels.The code works fine on exsting
records. When I attempt to print a new record I get Run-Time Error '94'
Invalid use of Null The code highlights on this line >> For L = 1 To
Forms!frmScan!ScanSub.Form.Parcels

You'll need to save the current record to disk:

If Me.Dirty Then Me.Dirty = False

will do it, before you'll be able to loop through the records.
 
R

Richard

John W. Vinson said:
You'll need to save the current record to disk:

If Me.Dirty Then Me.Dirty = False

will do it, before you'll be able to loop through the records.


Thanks John for the reply. I am still unsure on the direction I need to go.
I thought the me.dirty=false line saved the record? And if there is a value
in the Parcels textbox I shouldn't get an error.

Richard
 
J

John W. Vinson

Hi all,

I use the below code to print Dymo labels, the purpose is to print the
number of labels in the textbox TotalParcels.The code works fine on exsting
records. When I attempt to print a new record I get Run-Time Error '94'
Invalid use of Null The code highlights on this line >> For L = 1 To
Forms!frmScan!ScanSub.Form.Parcels

When I hover the mouse over the L it = 0
Thank you
Richard
------------------------------------------------------------------------------------------------
Private Sub Label5_Click()
Dim strWhere As String
Dim L As Long

If Me.Dirty Then
Me.Dirty = False
End If


If Me.NewRecord Then
MsgBox "Select a record to print"
Else
strWhere = "[ScanID] = " & Me.[ScanID]
End If


For L = 1 To Forms!frmScan!ScanSub.Form.Parcels
DoCmd.OpenReport "rptScanlogDymo", acViewNormal, , strWhere
Next L


DoCmd.GoToRecord , , acNewRec
Department.SetFocus

End Sub

Hrm. Apologies for the hasty answer previously!

What's in Forms!frmScan!ScanSub.Form.Parcels? Is the subform open and
populated? You'll get this error if that control is NULL or does not exist.
 
R

Richard

Hrm. Apologies for the hasty answer previously!
What's in Forms!frmScan!ScanSub.Form.Parcels? Is the subform open and
populated? You'll get this error if that control is NULL or does not exist.

Yes the subform is open and parcels is populated with a number

Richard
 
J

John W. Vinson

Yes the subform is open and parcels is populated with a number

Richard

If you step through the code in debug mode, what's in Parcel? What's in
strWhere?
 
J

John W. Vinson

:



parcels = 0

Well, that's the problem obviously. "Box 1 of 0"...
strWhere = 11

Although I do have a value in the subform.. (parcels)

Without more debugging than I can do at this distance I don't know what to
suggest. It's clearly not reading what you intend it to read as the loop
limit.
 
R

Richard

I think I may have figured this one out! I was referencing the wrong control
opps!
I referenced a bound control on the sub form called "parcels" instead of a
unbound control on the main form called "TotalParcels" oh my.

;P
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top