ADP SPROC Help

TR21Mark

Board Regular
Joined
Oct 30, 2004
Messages
240
Using Access 2007 ADP front end / SQL 2005 BE / Win7 x64

I have a form with unbound controls used for data entry. I have a stored procedure that is to append all of the fields into tblProjects.

What my code below does runs validation that each textbox is not null and if it passes then it runs a private sub that passes the parameters to the stored procedure. Right now I am having 2 issues with the code. The first is I am getting no error messages, the second is the data is not getting input into the table.

Could someone review my code and steer me in the right direction please? Thank in advance and appreciate any help that is given.

Code:
Private Sub cmdSaveProj_Click()
    ' Comments:
    ' Params  :
    ' Modified: MWJ 07192011
    
    'This checks all controls on the form with the word "ACE" in the Tag property of the control
    'If any of the controls are null or empty then the user can not proceed
    
    On Error GoTo PROC_ERR
    
    Dim objCtl As Object
    
    For Each objCtl In Me.Controls
        If (objCtl.ControlType = acTextBox Or objCtl.ControlType = acComboBox) And objCtl.Tag = "ACE" Then
            
            If Nz(objCtl, "") = "" Then
                MsgBox ("You can't exit this form until ALL data is provided!" & vbCrLf & "Enter the missing data and try again . . . "), , "MISSING DATA"
                objCtl.SetFocus
                
                Exit For
            End If
            
        End If
        'Insert below this line the commands you want if validation is met
        'Me.cmdCreateFC.Visible = True
        Call AddProject
        
    Next objCtl
    

    
PROC_EXIT:
    Exit Sub
    
PROC_ERR:
    MsgBox Err.Description, vbCritical, Me.Name & ".cmdSaveProj_Click"
    Resume PROC_EXIT




End Sub

Private Sub Form_AfterUpdate()

End Sub


Private Sub AddProject()
    Dim cn As ADODB.Connection
    Dim cmd As ADODB.Command
    
    Set cmd = New ADODB.Command
    Set cn = New ADODB.Connection
    cn.Open "my conn left out on purpose"
    
    On Error GoTo PROC_ERR
    
    With cmd
            Set .ActiveConnection = cn
            .CommandText = "mjspAddNewProject"
            .CommandType = adCmdStoredProc
            
           
            .Parameters.Append .CreateParameter("@ProjName", adVarChar, adParamInput, 100, Me.txtJobName)
            .Parameters.Append .CreateParameter("@ProjNo", adVarChar, adParamInput, 20, Me.txtJobNo)
            .Parameters.Append .CreateParameter("@ProjS1", adVarChar, adParamInput, 60, Me.txtStreet1)
            .Parameters.Append .CreateParameter("@ProjS2", adVarChar, adParamInput, 60, Me.txtStreet2)
            .Parameters.Append .CreateParameter("@ProjCity", adVarChar, adParamInput, 50, Me.txtCity)
            .Parameters.Append .CreateParameter("@ProjState", adVarChar, adParamInput, 5, Me.txtState)
            .Parameters.Append .CreateParameter("@ProjZip", adVarChar, adParamInput, 15, Me.txtZip)
            .Parameters.Append .CreateParameter("@ProjGC", adVarChar, adParamInput, 85, Me.cboGCName)
            .Parameters.Append .CreateParameter("@ProjGCID", adVarChar, adParamInput, 20, Me.txtGCID)
            
            'keep adding lines above for each parameter/textbox or control
            
            .Execute
            Set .ActiveConnection = Nothing
            End With
            
    
    
PROC_EXIT:
    cn.Close
    Set cmd = Nothing
    Set cn = Nothing
    Exit Sub
    
PROC_ERR:
    MsgBox Err.Number, Err.Description, vbCritical, Me.Name & ".AddProject"
    Resume PROC_EXIT


End Sub
 
sSQL is your sql string - so either declare a variable sSQL and use it to hold the sql string or remove it and use whatever you were using before. It was there only by way of example.

ξ
 
Upvote 0

Excel Facts

Spell Check in Excel
Press F7 to start spell check in Excel. Be careful, by default, Excel does not check Capitalized Werds (whoops)
Thanks,

I removed the sSQL and comma and it is working now. Thanks so much for this great tidbit of knowledge. Now I have one place to change the connection string.
 
Upvote 0

Forum statistics

Threads
1,224,568
Messages
6,179,595
Members
452,927
Latest member
whitfieldcraig

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top