bakershawnm
Programmer
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
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