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 | | | | re: Open forms using Openargs
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 | | | | re: Open forms using Openargs
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" <Kerkeslager@comcast.net> wrote in message
news:BvKdnQhNx9qSyCHcRVn-pw@comcast.com...[color=blue]
> Pass a string as your argument that contains the month data + a percent[/color]
sign[color=blue]
> (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
>
>[/color] | | | | re: Open forms using Openargs
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 | | | | re: Open forms using Openargs
Thanks HJ, that's a great help for me
Tony
"HJ" <hjiscoolno@spamhotmail.com> wrote in message
news:41bc72d3$0$42417$e4fe514c@news.xs4all.nl...[color=blue]
> Hi Tony,
>
> Darryl's code goes into the Form_Load event. I have made an example for[/color]
your[color=blue]
> 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
>
>[/color] | | | | re: Open forms using Openargs
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:cphibf$16i$1@titan.btinternet.com...[color=blue]
>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()[/color]
[color=blue]
>
> 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
>
>[/color] | | | | re: Open forms using Openargs
Thanks Tony
"Tony D'Ambra" <tdambra@swiftdsl.com.au> wrote in message
news:41bcc3bd$0$21871$61ce578d@news.syd.swiftdsl.c om.au...[color=blue]
> 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:cphibf$16i$1@titan.btinternet.com...[color=green]
> >I have two forms, frma and frmb, both are for inputting new records and[/color][/color]
are[color=blue][color=green]
> > 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[/color][/color]
frmb[color=blue][color=green]
> > I am using this code on the command button on frma:
> > Private Sub cmdOpenform_Click()[/color]
>[color=green]
> >
> > 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[/color][/color]
can't[color=blue][color=green]
> > create the new record because it already exists.
> > Can anyone help?
> > TIA
> > Tony Williams
> >
> >[/color]
>
>[/color] | | | | re: Open forms using Openargs
I've now had chance to implement the code HJ, although it passes the values
Ok I'm getting a message from the second form that saving the record would
create duplicates? The field txtmonth is the key field and set to no
duplicates. if the Openform code says acFormedit why is it trying to create
another record in my table?
Any help would be appreciated.
Thanks
Tony
"HJ" <hjiscoolno@spamhotmail.com> wrote in message
news:41bc72d3$0$42417$e4fe514c@news.xs4all.nl...[color=blue]
> Hi Tony,
>
> Darryl's code goes into the Form_Load event. I have made an example for[/color]
your[color=blue]
> 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
>
>[/color] | | | | re: Open forms using Openargs
Tony just a point. Why do I need to allow duplicates. I don't want the user
to create duplicate values in the table? I've got code as you suggest but am
getting an unable to save message because it would create a duplicate which
I don't want.
Tony
"Tony D'Ambra" <tdambra@swiftdsl.com.au> wrote in message
news:41bcc3bd$0$21871$61ce578d@news.syd.swiftdsl.c om.au...[color=blue]
> 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:cphibf$16i$1@titan.btinternet.com...[color=green]
> >I have two forms, frma and frmb, both are for inputting new records and[/color][/color]
are[color=blue][color=green]
> > 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[/color][/color]
frmb[color=blue][color=green]
> > I am using this code on the command button on frma:
> > Private Sub cmdOpenform_Click()[/color]
>[color=green]
> >
> > 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[/color][/color]
can't[color=blue][color=green]
> > create the new record because it already exists.
> > Can anyone help?
> > TIA
> > Tony Williams
> >
> >[/color]
>
>[/color] | | | | re: Open forms using Openargs
I've set up duplicate key and set duplicates to yes but still get the no
duplicate error message strange?????
Tony
"Tony D'Ambra" <tdambra@swiftdsl.com.au> wrote in message
news:41bcc3bd$0$21871$61ce578d@news.syd.swiftdsl.c om.au...[color=blue]
> 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:cphibf$16i$1@titan.btinternet.com...[color=green]
> >I have two forms, frma and frmb, both are for inputting new records and[/color][/color]
are[color=blue][color=green]
> > 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[/color][/color]
frmb[color=blue][color=green]
> > I am using this code on the command button on frma:
> > Private Sub cmdOpenform_Click()[/color]
>[color=green]
> >
> > 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[/color][/color]
can't[color=blue][color=green]
> > create the new record because it already exists.
> > Can anyone help?
> > TIA
> > Tony Williams
> >
> >[/color]
>
>[/color] | | | | re: Open forms using Openargs
Tony,
Do you want to add a new record or edit an existing one? For a new record
only, use:
DoCmd.OpenForm "frmb", , , , acFormAdd, acDialog, strArgs
If you are editing, use the Open action you have, but then you will need to
do a FindRecord for the record you want to edit
Darryl Kerkeslager
"Tony Williams" <tw@tcpinvalid.com> wrote in message
news:cpkrbq$65s$1@hercules.btinternet.com...[color=blue]
> I've now had chance to implement the code HJ, although it passes the[/color]
values[color=blue]
> Ok I'm getting a message from the second form that saving the record would
> create duplicates? The field txtmonth is the key field and set to no
> duplicates. if the Openform code says acFormedit why is it trying to[/color]
create[color=blue]
> another record in my table?
> Any help would be appreciated.
> Thanks
> Tony
> "HJ" <hjiscoolno@spamhotmail.com> wrote in message
> news:41bc72d3$0$42417$e4fe514c@news.xs4all.nl...[color=green]
> > Hi Tony,
> >
> > Darryl's code goes into the Form_Load event. I have made an example for[/color]
> your[color=green]
> > code, see below. The code in the cmdOpenForm_Click procedure assumes[/color][/color]
that[color=blue][color=green]
> > 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
> >
> >[/color]
>
>[/color] | | | | re: Open forms using Openargs
Tony Williams wrote:[color=blue]
> Tony just a point. Why do I need to allow duplicates. I don't want the user
> to create duplicate values in the table? I've got code as you suggest but am
> getting an unable to save message because it would create a duplicate which
> I don't want.
> Tony[/color]
Think about setting no duplicates on a month field.
What would be the max number of allowed records? | | | | re: Open forms using Openargs
Darryl the user completes the input in two stages first frma then frmb. As
both are based on the same table once frma has been saved then the values of
txtmonth will have been saved to the table. So I assume that when opening
frmb it's an edit procedure as the txtmonth value which is being passed is
already there. However even using the edit action I'm getting the duplicate
data error message.
Any ideas?
Thanks
Tony
"Darryl Kerkeslager" <Kerkeslager@comcast.net> wrote in message
news:tfGdnUE_hLBTvCPcRVn-uA@comcast.com...[color=blue]
> Tony,
>
> Do you want to add a new record or edit an existing one? For a new record
> only, use:
>
> DoCmd.OpenForm "frmb", , , , acFormAdd, acDialog, strArgs
>
> If you are editing, use the Open action you have, but then you will need[/color]
to[color=blue]
> do a FindRecord for the record you want to edit
>
>
>
> Darryl Kerkeslager
>
>
> "Tony Williams" <tw@tcpinvalid.com> wrote in message
> news:cpkrbq$65s$1@hercules.btinternet.com...[color=green]
> > I've now had chance to implement the code HJ, although it passes the[/color]
> values[color=green]
> > Ok I'm getting a message from the second form that saving the record[/color][/color]
would[color=blue][color=green]
> > create duplicates? The field txtmonth is the key field and set to no
> > duplicates. if the Openform code says acFormedit why is it trying to[/color]
> create[color=green]
> > another record in my table?
> > Any help would be appreciated.
> > Thanks
> > Tony
> > "HJ" <hjiscoolno@spamhotmail.com> wrote in message
> > news:41bc72d3$0$42417$e4fe514c@news.xs4all.nl...[color=darkred]
> > > Hi Tony,
> > >
> > > Darryl's code goes into the Form_Load event. I have made an example[/color][/color][/color]
for[color=blue][color=green]
> > your[color=darkred]
> > > code, see below. The code in the cmdOpenForm_Click procedure assumes[/color][/color]
> that[color=green][color=darkred]
> > > 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
> > >
> > >[/color]
> >
> >[/color]
>
>[/color] | | | | re: Open forms using Openargs
The tblmonth should have no duplicates in the txtmonth field but in the
linked table there could be upto 100 records per month
Tony
"rkc" <rkc@rochester.yabba.dabba.do.rr.bomb> wrote in message
news:iVpvd.51624$Uf.17304@twister.nyroc.rr.com...[color=blue]
> Tony Williams wrote:[color=green]
> > Tony just a point. Why do I need to allow duplicates. I don't want the[/color][/color]
user[color=blue][color=green]
> > to create duplicate values in the table? I've got code as you suggest[/color][/color]
but am[color=blue][color=green]
> > getting an unable to save message because it would create a duplicate[/color][/color]
which[color=blue][color=green]
> > I don't want.
> > Tony[/color]
>
> Think about setting no duplicates on a month field.
> What would be the max number of allowed records?[/color] | | | | re: Open forms using Openargs
Ah, that was confusing me. Before you go down this path any further, you
might want to really consider if this two-form thing is even necessary.
Unless there is some real need, using two forms to edit the same table seems
avoidable.
If this is in fact the way you want to do this, you have a couple of
options. You cannot just insert the primary key (id) field value into the
textbox that is bound to the id. You have to move BForm's current record to
that id.
Assuming AForm and BForm are based on the same table, which is not filtered,
and you want to edit a record from the table in BForm that you have selected
in AForm, all you would need to do is pass the primary key. You can do this
in the OpenArgs, or use the Where clause parameter of the Open method. If
you use the OpenArgs, then you will need to do one of two things in the
BForm's OnLoad event (where "id" is the primary keuy field):
1. Set the FormB recordsource
Me.RecordSource = "SELECT * FROM tblAddress WHERE tblAddress_id=" & id
2. Use some variation of a Find:
Me.txtId.SetFocus ' a textbox on BForm whose controlsource is the id
DoCmd.FindRecord id
or
Dim rsc As Object
Set rsc = Me.Recordset.Clone
With rsc
.FindFirst "address_id=" & id
If Not .EOF Then
Me.Bookmark = .Bookmark
End If
End With
Set rsc = Nothing
Darryl Kerkeslager
"Tony Williams" <tw@tcpinvalid.com> wrote in message
news:cpme9t$guk$1@hercules.btinternet.com...[color=blue]
> Darryl the user completes the input in two stages first frma then frmb. As
> both are based on the same table once frma has been saved then the values[/color]
of[color=blue]
> txtmonth will have been saved to the table. So I assume that when opening
> frmb it's an edit procedure as the txtmonth value which is being passed is
> already there. However even using the edit action I'm getting the[/color]
duplicate[color=blue]
> data error message.
> Any ideas?
> Thanks
> Tony
> "Darryl Kerkeslager" <Kerkeslager@comcast.net> wrote in message
> news:tfGdnUE_hLBTvCPcRVn-uA@comcast.com...[color=green]
> > Tony,
> >
> > Do you want to add a new record or edit an existing one? For a new[/color][/color]
record[color=blue][color=green]
> > only, use:
> >
> > DoCmd.OpenForm "frmb", , , , acFormAdd, acDialog, strArgs
> >
> > If you are editing, use the Open action you have, but then you will need[/color]
> to[color=green]
> > do a FindRecord for the record you want to edit
> >
> >
> >
> > Darryl Kerkeslager
> >
> >
> > "Tony Williams" <tw@tcpinvalid.com> wrote in message
> > news:cpkrbq$65s$1@hercules.btinternet.com...[color=darkred]
> > > I've now had chance to implement the code HJ, although it passes the[/color]
> > values[color=darkred]
> > > Ok I'm getting a message from the second form that saving the record[/color][/color]
> would[color=green][color=darkred]
> > > create duplicates? The field txtmonth is the key field and set to no
> > > duplicates. if the Openform code says acFormedit why is it trying to[/color]
> > create[color=darkred]
> > > another record in my table?
> > > Any help would be appreciated.
> > > Thanks
> > > Tony
> > > "HJ" <hjiscoolno@spamhotmail.com> wrote in message
> > > news:41bc72d3$0$42417$e4fe514c@news.xs4all.nl...
> > > > Hi Tony,
> > > >
> > > > Darryl's code goes into the Form_Load event. I have made an example[/color][/color]
> for[color=green][color=darkred]
> > > your
> > > > code, see below. The code in the cmdOpenForm_Click procedure assumes[/color]
> > that[color=darkred]
> > > > 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
> > > >
> > > >
> > >
> > >[/color]
> >
> >[/color]
>
>
>[/color] | | | | re: Open forms using Openargs
Hi Tony,
This confuses me, too. It seems odd to add a record to a table with two
separate forms. What kind of application are you developing? Maybe there is
a better way to fill this table than the use of two forms.
HJ |  | Similar Microsoft Access / VBA bytes | | | /bytes/about
We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights.
Get the best answers to your questions from over 226,374 network members.
|