In what way is it not working?
The way I see things happening is this:
When you open the second form from the first form the second form's
underlying query includes a reference to the current account number on the
first form, so if the second form's underlying table includes records with
that account number the second form will show those records.
If, however, you've just added a new customer record in the first form there
will not yet be any matching records in the second form's underlying table,
so the second form will open at a new record. The same would happen if the
first form is at an existing customer record, but no matching record yet
exists in the second form's underlying table.
In both of the latter scenarios you'd want the second form to open at a new
record, but with the value of the account number already in place. This is
what passing the account number from the first form to the second form as the
OpenArgs argument of the OpenForm method is for. Once that value is passed
the value of the account number will become the OpenArgs property of the
second form, so you can then use it to set the DefaultValue property of the
account number control on the second form, which is what the code in its Open
event procedure does. Once the DefaultValue property has been set for the
second form that value will appear in the account number control when the
second form is at a new record.
As I said in my last post the DefaultValue property is always a string
expression so its value should be wrapped in quotes. To include a quotes
character in a literal string you use two quotes characters, so the set of
four quotes characters is made up of two to delimit the literal string in the
usual way, and two within these, which are interpreted as one quotes
character. By concatenating these before and after the value of the form's
OpenArgs property this evaluates to that value wrapped in quotes.
I'm not quite sure what you mean by 'I cannot find property default value in
open events procedure'. You don't need to 'find' it as the code sets its
value for you at runtime. Just select the On Open event property in the
properties sheet of the second form in design view; click on the 'build'
button (the one on the right with 3 dots); select 'Code Builder' in the next
dialogue; when the VBA editor opens at the form's Open event procedure enter
the 3 lines of code between the 2 lines already in place; then save the form.
You'd do the same sort of thing in the first form to enter the code for the
Click event procedure of a button to open the second form and pass the
account number to it with the code I gave you for this.
Stevene James said:
thanks for your help.
However i cannot get this to work.
below you say
Then in the other form's Open event procedure set the DefaultValue property
of the Account Number to the value passed to it, testing for Null in case the
form is opened independently of the first form:
If Not IsNull(Me.OpenArgs) Then
Me.[Account Num].DefaultValue = """" & Me.OpenArgs & """"
End If
can you expand on your explanation a bit more. As i cannot find property
default value in open events procedure.
Regards