467,885 Members | 1,272 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 467,885 developers. It's quick & easy.

Open forms using Openargs

I have two forms, frma and frmb, both are for inputting new records and are
based on a table, tblmonth, both have two controls, txtmonth and
txtmonthlabela which are based on the fields in the table.
frma has a command button that opens frmb. I want the command buuton to pass
the value of txtmonth and txtmonthlabela from frma to the controls on frmb
I am using this code on the command button on frma:
Private Sub cmdOpenform_Click()
On Error GoTo Err_cmdOpenform_Click

DoCmd.OpenForm "frmb", , , , acFormEdit, , Me.txtMonth
DoCmd.Close acForm, Me.Name
Exit_cmdOpenform_Click:
Exit Sub

Err_cmdOpenform_Click:
MsgBox Err.Description
Resume Exit_cmdOpenform_Click
End Sub

and this code on the onload event of frmb:
Private Sub Form_Load()
If Len(Me.OpenArgs & "") > 0 Then
Me.txtMonth = Me.OpenArgs
Me.txtMonth.SetFocus
End If

End Sub

The code at the moment only passes the value of txtmonth and I want to pass
the value of txtmonthlabela as well. Also because txtmonth has the no
duplicates property set on the field I get an error message to say I can't
create the new record because it already exists.
Can anyone help?
TIA
Tony Williams
Nov 13 '05 #1
  • viewed: 8677
Share:
5 Replies
Pass a string as your argument that contains the month data + a percent sign
(or something that would never be part of an actual value) + month label
data. Then, in your OnLoad code, parse out the two separate Strings:
Dim i As Integer
Dim s As String
s = CStr(Me.OpenArgs)
i = InStr(1, s, "%")
Me.txtmonth = Left$(s, i - 1)
Me.txtmonthlabela = Mid$(s, i + 1)
Darryl Kerkeslager
Nov 13 '05 #2
Darryl I'm a newbie so that went a bit over my head.
Does this code go in the onclick expression or in the onload? How do I get
pick up both values from the first form? In other words how does your code
relate to the code I posted? Any ideas on my second part of my question?
Thanks for your help
Tony
"Darryl Kerkeslager" <Ke*********@comcast.net> wrote in message
news:Bv********************@comcast.com...
Pass a string as your argument that contains the month data + a percent sign (or something that would never be part of an actual value) + month label
data. Then, in your OnLoad code, parse out the two separate Strings:
Dim i As Integer
Dim s As String
s = CStr(Me.OpenArgs)
i = InStr(1, s, "%")
Me.txtmonth = Left$(s, i - 1)
Me.txtmonthlabela = Mid$(s, i + 1)
Darryl Kerkeslager

Nov 13 '05 #3
HJ
Hi Tony,

Darryl's code goes into the Form_Load event. I have made an example for your
code, see below. The code in the cmdOpenForm_Click procedure assumes that
both values are actually entered and that these do not contain the %
character (as Darryl already suggested).

HJ

frma: cmdOpenForm_Click

Private Sub cmdOpenForm_Click()
On Error GoTo Err_cmdOpenform_Click

Dim strArgs As String
strArgs = Me.txtMonth & "%" & Me.txtMonthLabelA

DoCmd.OpenForm "frmb", , , , acFormEdit, , strArgs
DoCmd.Close acForm, Me.Name

Exit_cmdOpenform_Click:
Exit Sub

Err_cmdOpenform_Click:
MsgBox Err.Description
Resume Exit_cmdOpenform_Click

End Sub
frmb: Form_Load

Private Sub Form_Load()

If Len(Me.OpenArgs & "") > 0 Then
Dim i As Integer
Dim s As String
s = CStr(Me.OpenArgs)
i = InStr(1, s, "%")
Me.txtMonth = Left$(s, i - 1)
Me.txtMonthLabelA = Mid$(s, i + 1)
Me.txtMonth.SetFocus
End If

End Sub
Nov 13 '05 #4
Thanks HJ, that's a great help for me
Tony
"HJ" <hj********@spamhotmail.com> wrote in message
news:41***********************@news.xs4all.nl...
Hi Tony,

Darryl's code goes into the Form_Load event. I have made an example for your code, see below. The code in the cmdOpenForm_Click procedure assumes that
both values are actually entered and that these do not contain the %
character (as Darryl already suggested).

HJ

frma: cmdOpenForm_Click

Private Sub cmdOpenForm_Click()
On Error GoTo Err_cmdOpenform_Click

Dim strArgs As String
strArgs = Me.txtMonth & "%" & Me.txtMonthLabelA

DoCmd.OpenForm "frmb", , , , acFormEdit, , strArgs
DoCmd.Close acForm, Me.Name

Exit_cmdOpenform_Click:
Exit Sub

Err_cmdOpenform_Click:
MsgBox Err.Description
Resume Exit_cmdOpenform_Click

End Sub
frmb: Form_Load

Private Sub Form_Load()

If Len(Me.OpenArgs & "") > 0 Then
Dim i As Integer
Dim s As String
s = CStr(Me.OpenArgs)
i = InStr(1, s, "%")
Me.txtMonth = Left$(s, i - 1)
Me.txtMonthLabelA = Mid$(s, i + 1)
Me.txtMonth.SetFocus
End If

End Sub

Nov 13 '05 #5
1. In frma, declare a string variable srtDateMonth, and pass it with the
following value = Me.txtmonth.Value & "," & Me.txtmonthlabela.Value. In
frmb, parse the srtDateMonth value into the two values using the InStr and
Mid functions.

2. In the table, set allow duplicates "yes" for the txtmonth field and
create a joint Primary Key on txtmonth and the existing primary key.

--
Tony D'Ambra
Web Site: aadconsulting.com
Web Blog: accessextra.net

"Tony Williams" <tw@tcpinvalid.com> wrote in message
news:cp**********@titan.btinternet.com...
I have two forms, frma and frmb, both are for inputting new records and are
based on a table, tblmonth, both have two controls, txtmonth and
txtmonthlabela which are based on the fields in the table.
frma has a command button that opens frmb. I want the command buuton to
pass
the value of txtmonth and txtmonthlabela from frma to the controls on frmb
I am using this code on the command button on frma:
Private Sub cmdOpenform_Click()
DoCmd.OpenForm "frmb", , , , acFormEdit, , Me.txtMonth
DoCmd.Close acForm, Me.Name
Exit_cmdOpenform_Click:
Exit Sub

Err_cmdOpenform_Click:
MsgBox Err.Description
Resume Exit_cmdOpenform_Click
End Sub

and this code on the onload event of frmb:
Private Sub Form_Load()
If Len(Me.OpenArgs & "") > 0 Then
Me.txtMonth = Me.OpenArgs
Me.txtMonth.SetFocus
End If

End Sub

The code at the moment only passes the value of txtmonth and I want to
pass
the value of txtmonthlabela as well. Also because txtmonth has the no
duplicates property set on the field I get an error message to say I can't
create the new record because it already exists.
Can anyone help?
TIA
Tony Williams

Nov 13 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

9 posts views Thread by Shyguy | last post: by
15 posts views Thread by Tony Williams | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.