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

Runtime error 13 type mismatch on scroll to empty record 1

Status
Not open for further replies.

NewTexican

Technical User
Dec 10, 2004
95
US
I have a pop up that relates to a parent form and changes as user scrolls through parent form. I'm getting "Runtime error 13 type mismatch" when I scroll to an empty record on the parent form. Debug takes me to either the highlighted line or the code on a subform that points to this sub.

Public Sub updatecontrols()
Dim db As Database
Dim rstable As DAO.Recordset
Dim sqllst1, sqllst2 As String
Dim mail1, mail2 As Boolean
Dim compnum As Variant
Dim addtype As Variant
Dim compname As Variant

compnum = Me.Text18
addtype = Me.Text20
compname = Forms![common company].[company name]

[highlight] Me!Label45.Caption = compname [/highlight]
Me!Label46.Caption = addtype & " Address Mailouts"

Set db = CurrentDb
Set rstable = db.OpenRecordset("Company-Mailout T", dbOpenDynaset)

sqllst1 = "[company numeric] = " & compnum & " and [address type] = " & "'" & addtype & "'" & " and [mailout] = 'c mailout 1'"
sqllst2 = "[company numeric] = " & compnum & " and [address type] = " & "'" & addtype & "'" & " and [mailout] = 'c mailout 2'"
rstable.FindFirst sqllst1
Me!Check12.Value = (Not rstable.NoMatch) And rstable![Send mailout]
rstable.FindFirst sqllst2
Me!Check14.Value = (Not rstable.NoMatch) And rstable![Send mailout]
rstable.Close
End Sub

I thought maybe changing my variables to type variant would solve this, but it doesn't. Thanks.
 
compname is declared as a variant, which accepts Null. The caption of a label does not. Try:

[tt] Me!Label45.Caption = nz(compname,"") [/tt]

Roy-Vidar
 
that definitely did something I didn't know about Nz, thanks.

now I'm getting this error

run time error 3077
syntax error (missing operator) in expression

Debug takes me to the code on a subform that calls the code I originally posted above
This is what points:
Forms![company mailout f].updatecontrols
 
Strange error. If you excuse me, I think also the setup/how you run this, well, it is a bit unfamiliar. How many forms do you have open? [common company], [company mailout f] and... you're sure all referenced forms are open?

If this is from a subform, you could also use

[tt]me.parent.updatecontrols[/tt]

I think, but that probably won't solve anything. Same with the other reference

[tt]compname = me.parent.Form![company name][/tt]

I'd perhaps just not run this routine if the form reference was Null (the parent form has "an empty record" - you mean a new record?).

Perhaps:

[tt]if trim$(Forms![common company].[company name] & "")<>"" then
' perform all your code
end if[/tt]

Trim thingie - is also a Null test, testing both for Null, "" and only spaces. If empty record means new record, you could try substitute the test with

[tt]if not Forms![common company].newrecord then[/tt]

I'd also release the object variables at the end of the routine:

[tt]set rs=nothing
set db=nothing[/tt]

Roy-Vidar
 
It was a new record that was messing it up. The if not you recommended works very well.
Thanks for the tip on releasing my variables.
so much to know.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top