Autofill form fields

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hello,

I have 2 forms in an inventory DB. I need to create a button on the first
form that opens a new record in the second form with some data from the open
field in the first formula.

I know how to get the button to open the new record, but I can't get it to
pre-fill the desired fields.

Can anyone help?

Thanks in advance,
Rogerio.
 
You can pass the fields values using the OpenArgs, put a seperator between
them, like ($) Something that wont come up in the string

DoCmd.OpenForm DocName, , , ,acFormAdd , ,Me.[Field1] & "$" & Me.[Field2]


On the OnLoad event of the second form form, write the code to split the open
args and assign it to the text boxes

If Me.NewRecord Then
Me.[Field1] = Split(Me.OpenArgs,"$")(0)
Me.[Field2] = Split(Me.OpenArgs,"$")(1)
End If
 
Hi Ofer,

First of all, thanks for you super-quick reply.
Where should I put the first piece of code? Somewhere in the first form, I'm
guessing, but where?
 
In the first form create a button, in the button click event select code and
enter this line of code, make sure that you pass the right fields names

DoCmd.OpenForm DocName, , , ,acFormAdd , ,Me.[Field1] & "$" & Me.[Field2]


On the OnLoad event of the second form form, write the code to split the open
args and assign it to the text boxes

If Me.NewRecord Then
Me.[Field1] = Split(Me.OpenArgs,"$")(0)
Me.[Field2] = Split(Me.OpenArgs,"$")(1)
End If
--
Good Luck
BS"D


RogerSoft said:
Hi Ofer,

First of all, thanks for you super-quick reply.
Where should I put the first piece of code? Somewhere in the first form, I'm
guessing, but where?

Ofer Cohen said:
You can pass the fields values using the OpenArgs, put a seperator between
them, like ($) Something that wont come up in the string

DoCmd.OpenForm DocName, , , ,acFormAdd , ,Me.[Field1] & "$" & Me.[Field2]


On the OnLoad event of the second form form, write the code to split the open
args and assign it to the text boxes

If Me.NewRecord Then
Me.[Field1] = Split(Me.OpenArgs,"$")(0)
Me.[Field2] = Split(Me.OpenArgs,"$")(1)
End If
 
Thanks a lot, that was exactly it!!

Ofer Cohen said:
In the first form create a button, in the button click event select code and
enter this line of code, make sure that you pass the right fields names

DoCmd.OpenForm DocName, , , ,acFormAdd , ,Me.[Field1] & "$" & Me.[Field2]


On the OnLoad event of the second form form, write the code to split the open
args and assign it to the text boxes

If Me.NewRecord Then
Me.[Field1] = Split(Me.OpenArgs,"$")(0)
Me.[Field2] = Split(Me.OpenArgs,"$")(1)
End If
--
Good Luck
BS"D


RogerSoft said:
Hi Ofer,

First of all, thanks for you super-quick reply.
Where should I put the first piece of code? Somewhere in the first form, I'm
guessing, but where?

Ofer Cohen said:
You can pass the fields values using the OpenArgs, put a seperator between
them, like ($) Something that wont come up in the string

DoCmd.OpenForm DocName, , , ,acFormAdd , ,Me.[Field1] & "$" & Me.[Field2]


On the OnLoad event of the second form form, write the code to split the open
args and assign it to the text boxes

If Me.NewRecord Then
Me.[Field1] = Split(Me.OpenArgs,"$")(0)
Me.[Field2] = Split(Me.OpenArgs,"$")(1)
End If
 

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

Back
Top