cancel form and variables in data environment

From: news.microsoft.com (noidea_at_nospam.com)
Date: 10/25/04


Date: Mon, 25 Oct 2004 14:44:54 +0100

Hi,

I am a complete newbie so please bear with me . . .

I have only one form in my project that displays 4 datagrid control totals
based on designers that are base on paramaterised stored procedures in SQL
Server. At the moment I have entered the values for the parameters but I
would like these take the value from a variable that is found using the
following code.

Q1) How do I set the parameter values at runtime rather than having to put
them into the designer? I have tried replacing the value with the variable
name but this doesn't seem to work.

Q2) How can I cancel the loading of a form if the variable is not set?

Here is what I have so far in the

Separate Module:
Public strYear as string
Public strMonth as string
*********************
Private Sub Form_Initialize()

Dim conMIS As ADODB.Connection
Dim cmdCurrentPeriod As ADODB.Command
Dim rsCurrentPeriod As ADODB.Recordset
Dim params As ADODB.Parameters

On Error GoTo errorhandling

Set conMIS = New ADODB.Connection
Set cmdCurrentPeriod = New ADODB.Command
Set rsCurrentPeriod = New ADODB.Recordset

conMIS.ConnectionString = "Provider=SQLOLEDB.1;Persist Security
Info=False;User ID=sa;pwd=mypassword;Initial Catalog=MyDatabase;Data
Source=MySQL"
conMIS.CursorLocation = adUseClient
conMIS.Open

With cmdCurrentPeriod
    Set .ActiveConnection = conMIS
    .CommandText = "CurrentMonth"
    .CommandType = adCmdStoredProc
End With

Set rsCurrentPeriod = cmdCurrentPeriod.Execute
If rsCurrentPeriod.RecordCount > 0 Then
strYear = rsCurrentPeriod.Fields("FinYear")
strMonth = rsCurrentPeriod.Fields("FinMonth")
Else
Msgox "Current Period could not be established. The form will be closed."
CODE TO CANCEL LOADING OF THE FORM TO GO HERE BUT I DON'T KNOW HOW TO DO IT
End If
exit sub
errorhandling:
If err.number <> 0 then
msgbox err.number & " " & err.description
End If
End sub


Loading