Missed value passed throught OpenArgs

A

Alex Vizuete

hi, i have the following trouble:
i'm trying to pass an argument to a second form throught openargs, but when
i try to get the passed value from openargs it is nothing, i confirmed that
sArgs have a value at call

my call at the first form is

Private Sub CmdCatalogo_Click()
Dim fCtas As New Form_Frm_Cuentas
Dim sArgs As String

sArgs = CStr(iIdEmpresa) & "-" & sNomEmpresa
sName = fCtas.Name
DoCmd.OpenForm fCts.Name, , , , , , sArgs
Set fCtas = Nothing
End Sub

this code goes at the second form
Private Sub Form_Open(Cancel As Integer)
Dim sSqlStmt As String, sParam() As String

If Not IsNull(Me.OpenArgs) Then
sParam = Split(Me.OpenArgs, "-")

MsgBox "IdEmpresa = " & iIdEmpresa
sSqlStmt = "SELECT Cuentas.[P&L], Cuentas.Clss, Cuentas.Cat,
Cuentas.Group, Cuentas.Seq, " _
& "Cuentas.IMI_Code, Cuentas.[Group/Account_Name],
Cuentas.[Mercom_Code], Cuentas.Description " _
& "FROM Cuentas " _
& "WHERE IdEmpresa = " & CLng(sParam(0)) & " ORDER BY
Cuentas.[P&L], Cuentas.Clss, Cuentas.Cat, Cuentas.Group, Cuentas.Seq;"

Me.lblEmpresa.Caption = vbNullString
Me.lblEmpresa.Tag = vbNullString
If CLng(sParam(0)) = 0 Then
MsgBox "Seleccione la empresa de trabajo.", vbInformation
Cancel = True
Exit Sub
End If
Me.lblEmpresa.Caption = sParam(1)
Me.lblEmpresa.Tag = sParam(0)
Else
MsgBox "Debe seleccionar una empresa.", vbInformation
Cancel = True
End If
End Sub

aditionally at the second form when assign cancel=true i get an error "Run
time error 2001. You canceled the previous operation", at this line
"DoCmd.OpenForm fCts.Name, , , , , , sArgs"
in the first form

Best Regards,
Alex Vizuete

PD: sorry for my english...
 
M

Marshall Barton

It's not clear what you want to accomplish with this. If
you are trying to open multiple instances of the same form,
you can not use OpenForm to do it (and therefor you can not
use OpenArgs).

If you only want to open a single copy of the form, then do
not use Dim fCtas As New Form_Frm_Cuentas
In this case, use:

Private Sub CmdCatalogo_Click()
Dim sArgs As String
Dim sName As String
sArgs = CStr(iIdEmpresa) & "-" & sNomEmpresa
sName = "Frm_Cuentas"
DoCmd.OpenForm sName, OpenArgs:= sArgs
End Sub
--
Marsh
MVP [MS Access]




Alex said:
hi, i have the following trouble:
i'm trying to pass an argument to a second form throught openargs, but when
i try to get the passed value from openargs it is nothing, i confirmed that
sArgs have a value at call

my call at the first form is

Private Sub CmdCatalogo_Click()
Dim fCtas As New Form_Frm_Cuentas
Dim sArgs As String

sArgs = CStr(iIdEmpresa) & "-" & sNomEmpresa
sName = fCtas.Name
DoCmd.OpenForm fCts.Name, , , , , , sArgs
Set fCtas = Nothing
End Sub

this code goes at the second form
Private Sub Form_Open(Cancel As Integer)
Dim sSqlStmt As String, sParam() As String

If Not IsNull(Me.OpenArgs) Then
sParam = Split(Me.OpenArgs, "-")
[snip]
 
A

Alex Vizuete

Thanks Marshall, yes i just wanna a single copy , i corrected my code.

Thanks again,
Alex.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top