G
Guest
Below are instructions to autofill a simplier way than what is posted on
Microsoft Knowledge Base Article ID : 210236.
My problem is as I listed on a earlier post the Microsoft way I get all
fields autofilled (please see earlier post AUTOFILL PREVIOUS RECORD REPOST)
or this listed below which autofills proper field but the result is always 0
ie.. CustomerID 12 result in new record 0.
Hopefully somebody knows the answer to one of these delima's
TIA
The simplest way I can think for you to do this is with a little bit of VBA
code. You will need to put the form in design mode. Click on the Code
button on the tool bar. Just under the words “Option Compare Database†add
this line: Public current_boxnum as integer (or long or string depending upon
the field type Box # is)
Then go back to the form in design mode. Click on the Box # field and then
click on the Properties button on the tool bar. Select the Event tab. Click
on the field next to the “After Update†event. Then click on the button with
the three dots that appears to the right of this field. A little window pops
up, choose “Code Builder.†This brings you to the Visual Basic Window again.
It will have automatically generated something similar to what you see below
but it will actually have the name of your Box # field instead of BoxNum.
Private Sub BoxNum_AfterUpdate()
End Sub
Put the following code in so it now looks like this:
Private Sub BoxNum_AfterUpdate()
current_boxnum = BoxNum.value
End Sub
What the above does is saves a copy of the box # recently entered in the
form in a public variable that will have data for as long as the form is
open. When the form closes, the variable is erased. So, this procedure will
require the user to enter in the box number to the form each time the form is
opened for use.
Next, you will need to tell the form to autofill the Box # each time the
user is in a new record. So, you will need to go back to the form in design
mode, click on the square in the top left-hand side of the form window (to
the left of the ruler above the form header bar). If the Properties window
is not open still, click on the Properties button again. Make sure the Event
tab is clicked. Find the form’s On Current event, click on the field next to
it, then on the button with three dots, and choose “Code Builder.†Then
enter in the following code:
Private Sub Form_Current()
if me.newrecord and not isnull(current_boxnum) then
BoxNum.value = current_boxnum
end if
End Sub
What the above does is check to see if the user is in a new records (because
you don’t want to change the data in an existing record) and also check to
make sure that a value has been saved in the current_boxnum variable. Given
these two situations, you will then want to have the BoxNum value to be the
value that is being held in the current_boxnum variable.
Microsoft Knowledge Base Article ID : 210236.
My problem is as I listed on a earlier post the Microsoft way I get all
fields autofilled (please see earlier post AUTOFILL PREVIOUS RECORD REPOST)
or this listed below which autofills proper field but the result is always 0
ie.. CustomerID 12 result in new record 0.
Hopefully somebody knows the answer to one of these delima's
TIA
The simplest way I can think for you to do this is with a little bit of VBA
code. You will need to put the form in design mode. Click on the Code
button on the tool bar. Just under the words “Option Compare Database†add
this line: Public current_boxnum as integer (or long or string depending upon
the field type Box # is)
Then go back to the form in design mode. Click on the Box # field and then
click on the Properties button on the tool bar. Select the Event tab. Click
on the field next to the “After Update†event. Then click on the button with
the three dots that appears to the right of this field. A little window pops
up, choose “Code Builder.†This brings you to the Visual Basic Window again.
It will have automatically generated something similar to what you see below
but it will actually have the name of your Box # field instead of BoxNum.
Private Sub BoxNum_AfterUpdate()
End Sub
Put the following code in so it now looks like this:
Private Sub BoxNum_AfterUpdate()
current_boxnum = BoxNum.value
End Sub
What the above does is saves a copy of the box # recently entered in the
form in a public variable that will have data for as long as the form is
open. When the form closes, the variable is erased. So, this procedure will
require the user to enter in the box number to the form each time the form is
opened for use.
Next, you will need to tell the form to autofill the Box # each time the
user is in a new record. So, you will need to go back to the form in design
mode, click on the square in the top left-hand side of the form window (to
the left of the ruler above the form header bar). If the Properties window
is not open still, click on the Properties button again. Make sure the Event
tab is clicked. Find the form’s On Current event, click on the field next to
it, then on the button with three dots, and choose “Code Builder.†Then
enter in the following code:
Private Sub Form_Current()
if me.newrecord and not isnull(current_boxnum) then
BoxNum.value = current_boxnum
end if
End Sub
What the above does is check to see if the user is in a new records (because
you don’t want to change the data in an existing record) and also check to
make sure that a value has been saved in the current_boxnum variable. Given
these two situations, you will then want to have the BoxNum value to be the
value that is being held in the current_boxnum variable.