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

Passing a form as an optional paramater 2

Status
Not open for further replies.

bakershawnm

Programmer
Apr 18, 2007
84
US
I have the following function:

Public Function set_globals(Optional frm as Form)
On Error GoTo Err_SG

Dim spccnxn As New ADODB.Connection
DataSrc = Application.CurrentProject.Path & "\" & Application.CurrentProject.Name
lclcnxn.ConnectionString = "Provider='Microsoft.Jet.OLEDB.4.0';Data Source='" & DataSrc & "';Persist Security Info='False'"
If frm Is Not Nothing Then
spccnxn.ConnectionString = "Provider='MSDASQL.1';Persist Security Info='False';" & _
"Trusted_Connection=True;Data Source='SPCData';Initial Catalog='SPCData'"
spccnxn.Open
spccnxn.Execute "DELETE TOP (100) PERCENT FROM temptbl"

mysql = "INSERT INTO TempTbl (assy, src, stdt, enddt) " & _
"SELECT '" & frm!cboasm & "', '" & frm!SRC & "', '" & frm!BDt & "', '" & frm!EDt & "';"
spccnxn.Execute mysql
spccnxn.Close
Set spccnxn = Nothing
End If
Exit_SG:
Exit Function

Err_SG:
MsgBox Err.Number & "-" & Err.Description
Resume Exit_SG

End Function

At compile time I get the error Invalid use of Object flagging the Nothing.

I have tried the following (and all explicit variations) for the If statement:

If Not IsMissing(frm) Then

I did find this FAQ on here faq707-3710 but like all other explanations of IsMissing it never specifically mentions Forms working for this function. And VBA for Access does not have the IsNothing (which is what frm contains when it gets to the condition when I don't pass anything)

For now I am going to separate the function into two so I eliminate the need to pass a form as an optional. However I really would like to know the answer to this issue.

Thanks
 
What about this ?
Code:
Public Function set_globals(Optional frm As Form = Nothing)
...
If Not (frm Is Nothing) Then
...

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
The syntax for this is:
Code:
If Not frm Is Nothing then...
Hope this helps

HarleyQuinn
---------------------------------
Carter, hand me my thinking grenades!

You can hang outside in the sun all day tossing a ball around, or you can sit at your computer and do something that matters. - Eric Cartman

Get the most out of Tek-Tips, read FAQ222-2244: How to get the best answers before posting.

 
Darn slow typing [wink]

HarleyQuinn
---------------------------------
Carter, hand me my thinking grenades!

You can hang outside in the sun all day tossing a ball around, or you can sit at your computer and do something that matters. - Eric Cartman

Get the most out of Tek-Tips, read FAQ222-2244: How to get the best answers before posting.

 
Thanks to both of you. I guess it was a brain frt on my part. I though I tried that syntax for the IF, but I guess not cuz it worked. :)

Thanks and have a star
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top