Open a form using Openargs

T

Tony Williams

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
 
J

Jeff Boyce

Tony

You have two forms, both of which are based on a single table. You are
working with a record in one form, then want the second form to get the same
record (while the first form still "holds" it). I would expect to get an
error, too!

Could you provide a description of why you feel that two forms are needed --
it isn't clear what your perceived business need is that's driving this
approach. There may be other ways to achieve what you want to accomplish,
if the 'group knew what that is.

It isn't necessary to "pass" values in Access (other programming systems
might require this, but not Access). You could have a second form open and
take, as its values, those values present in the first form, by using
references like:

Forms!FormA!txtMonth
 
T

Tony Williams

Thanks Jeff.
This database collects two types of statistics, so I have a table for each
type. I have another table that holds the dates that the stats refer to and
as these dates are the same for each type of stats I've a common table that
holds the dates. So I have three tables table1 has a number of fields
holding 1 list of stats, table 2 has the other stats and table 3 holding the
dates.
I then have two forms
First form, forma, based on table 3 with a subform based on table 1 and
another form, formb, also based on table 3 with a subform based on table 2

The stats in the table 1 and table 2 are completely different but are for
the same dates
I put the date data in a table of its own so that the users would not have
to key it separately and risk errors
The idea is for the user to input data in the forma and then click on the
command button to open the formb carrying across the data from table 3
I hope I've managed to explain that OK
Thanks for you help
Tony
 
J

Jeff Boyce

Tony

You have a table of dates?

I'm still not clear on the business need for using separate tables for "each
type [of statistics]". And your definition of "statistics" and mine may not
match.

I'm wondering if you might not be able to solve your issue by using a single
table, but I still don't know enough about what you are recording to tell if
that makes sense.

Can you provide a few rows of example data?
 

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