I am having problems with this code, not sure where i am going wrong.
My code looks for values in a table prior to appending, if no records are present in the table an error message is displayed, allowing the user to choose to open a form to input new data in.
I get this message: "Argument not optional", pointing at my OpenConnection.
My sub is available in another form and I declared it as public as well as the variables. bellow is the code. They work in my form1, as I tested them before.
Code in form1:
Code in current form2:
My code looks for values in a table prior to appending, if no records are present in the table an error message is displayed, allowing the user to choose to open a form to input new data in.
I get this message: "Argument not optional", pointing at my OpenConnection.
My sub is available in another form and I declared it as public as well as the variables. bellow is the code. They work in my form1, as I tested them before.
Code in form1:
Code:
Option Explicit
' The member variables used throughout the project
Public XMLDoc As MSXML2.DOMDocument40
Public cnn As ADODB.Connection
Public rst As ADODB.Recordset
Public TypeName As String
' constant used throughout the code for when we want to
' save the document
Const XMLPath As String = "N:\Databases\XmlFile\download.xml"
Public Sub OpenConnection()
Set cnn = CurrentProject.Connection
End Sub
Public Sub CloseConnection()
cnn.Close
Set cnn = Nothing
End Sub
Code:
Private Sub cmdValidateInput_Click()
On Error GoTo Err_cmdValidateInput_Click
Dim sSQL As String
Dim intResponse As Variant
'Check to see if there are any values in the POPImport table.
intResponse = MsgBox("There are no values in the POP Import table. Would you like to add values now?", _
vbYesNo + vbQuestion, "Edit Table")
sSQL = "SELECT Count(qryPOPImport.intOrderNumber) AS CountOfOrder " & _
"FROM qryPOPImport;"
'Open connection to the database
OpenConnection
'set the recordset
Set rst = New ADODB.Recordset
rst.CursorType = adOpenStatic
rst.LockType = adLockOptimistic
rst.Open sSQL, cnn, adCmdText
'count the number of orders in the POP import table.
'Evaluate to proceed with the order processing
If rst.Fields("CountOfOrder") = 0 Then
'Give user the option to enter the new records.
If intResponse = vbYes Then
DoCmd.OpenForm "frmPOPImport", acFormDS, acEdit
Else
MsgBox "No new values"
End If
Else
'update Sku values in POP Import table
DoCmd.SetWarnings False
DoCmd.OpenQuery "udtImportPOPSku", acViewNormal, acReadOnly
DoCmd.SetWarnings True
ProcessPOPImport
End If
rst.Close
Set rst = Nothing
' Close Connection to database
CloseConnection
'Error handling
Exit_cmdValidateInput_Click:
Exit Sub
Err_cmdValidateInput_Click:
MsgBox Err.Description
Resume Exit_cmdValidateInput_Click
End Sub
Last edited: