form code to create field

B

bbypookins

I'm creating a database to track a particular form that we receive in our
office. When we receive the form we give it a unique number that combines the
division it came from and a sequential number pertaining to that division
only. In other words, when a form comes in from Executive, it will be given
the number EXE-001 and the next time one form Executive comes in it will be
EXE-002, and so on. When one from Finance & Administration comes in it will
be numbered FA-001, then FA-002, etc.

What I'd like to be able to do in the form is have a combo box field to
select the division from qryDivision and then have the sequential number be
generated automatically depending on what division you choose. Then, I'd like
those two fields to be combined in one field (RPA_No) in the main table
(tblRPALog).

I have no idea how to do this and I'm easily confused when it comes to coding.
 
K

Klatuu

I don't think you receive forms. Forms do not contain any data. Data is
contained in tables. Forms are used to present and manipulate data.
What are you actually receiving?
 
B

bbypookins

I'm talking about a hard copy form we that comes into our office. I'm
creating a database to log these forms.
 
K

Klatuu

LOL, Okay. Sorry, but my poor Access oriented brain sees form and translates
it into the Access Form object. Now it makes sense.

You will need an unbound control on your Access Form to select the division.
I would use a combo box. In your table, I would use 2 fields - one for the
Division and one for the number. In the After Update event of the combo box,
determine the current highest number for the selected division and add one
to it. Also, I would make this combo box invisible except for new records.

Private Sub cboDivisonSelect_AfterUpdate()

Me.txtDivision = Me.cboDivisionSelect
Me.txtSeqNumber = Nz(DLookup("[SeqNumber]", "TableName", "[Division] =
""" & Me.cboDivisionSelect & """"), 0) + 1

End Sub

Now in the Form Current Event:

With Me
If .NewRecord Then
.cboDivisionSelect.Visible = True
.cboDivisionSelect.SetFocus
Else
.cboDivisionSelect.Visible = False
End If

End Sub
 
B

bbypookins

The user needs to be able to quickly and easily access the record based on
that combined number. How would they do the field is not visible on the form
and is not logged in the table as one combined field?

Klatuu said:
You will need an unbound control on your Access Form to select the division.
I would use a combo box. In your table, I would use 2 fields - one for the
Division and one for the number. In the After Update event of the combo box,
determine the current highest number for the selected division and add one
to it. Also, I would make this combo box invisible except for new records.

Private Sub cboDivisonSelect_AfterUpdate()

Me.txtDivision = Me.cboDivisionSelect
Me.txtSeqNumber = Nz(DLookup("[SeqNumber]", "TableName", "[Division] =
""" & Me.cboDivisionSelect & """"), 0) + 1

End Sub

Now in the Form Current Event:

With Me
If .NewRecord Then
.cboDivisionSelect.Visible = True
.cboDivisionSelect.SetFocus
Else
.cboDivisionSelect.Visible = False
End If

End Sub
--
Dave Hargis, Microsoft Access MVP


bbypookins said:
I'm talking about a hard copy form we that comes into our office. I'm
creating a database to log these forms.
 
K

Klatuu

Notice the code for the form current event. That makes the the combo visible
for new records.

Then when the combo is made visible and the user selects a division, the
number is assigned and the bound controls are populated.

As to two fields compared to one combined field. Using two fields provides
more flexibility and make coding easier. Don't confuse what is carried in
the database with what is presented visually to the user. The user will see
both values. You can position the controls so the user sees the division and
number together.

The user has to select a division before a number can be created.
--
Dave Hargis, Microsoft Access MVP


bbypookins said:
The user needs to be able to quickly and easily access the record based on
that combined number. How would they do the field is not visible on the form
and is not logged in the table as one combined field?

Klatuu said:
You will need an unbound control on your Access Form to select the division.
I would use a combo box. In your table, I would use 2 fields - one for the
Division and one for the number. In the After Update event of the combo box,
determine the current highest number for the selected division and add one
to it. Also, I would make this combo box invisible except for new records.

Private Sub cboDivisonSelect_AfterUpdate()

Me.txtDivision = Me.cboDivisionSelect
Me.txtSeqNumber = Nz(DLookup("[SeqNumber]", "TableName", "[Division] =
""" & Me.cboDivisionSelect & """"), 0) + 1

End Sub

Now in the Form Current Event:

With Me
If .NewRecord Then
.cboDivisionSelect.Visible = True
.cboDivisionSelect.SetFocus
Else
.cboDivisionSelect.Visible = False
End If

End Sub
--
Dave Hargis, Microsoft Access MVP


bbypookins said:
I'm talking about a hard copy form we that comes into our office. I'm
creating a database to log these forms.

:

I don't think you receive forms. Forms do not contain any data. Data is
contained in tables. Forms are used to present and manipulate data.
What are you actually receiving?
--
Dave Hargis, Microsoft Access MVP


:

I'm creating a database to track a particular form that we receive in our
office. When we receive the form we give it a unique number that combines the
division it came from and a sequential number pertaining to that division
only. In other words, when a form comes in from Executive, it will be given
the number EXE-001 and the next time one form Executive comes in it will be
EXE-002, and so on. When one from Finance & Administration comes in it will
be numbered FA-001, then FA-002, etc.

What I'd like to be able to do in the form is have a combo box field to
select the division from qryDivision and then have the sequential number be
generated automatically depending on what division you choose. Then, I'd like
those two fields to be combined in one field (RPA_No) in the main table
(tblRPALog).

I have no idea how to do this and I'm easily confused when it comes to coding.
 
B

bbypookins

I'm still confused how one would search for a record based on the combo if
it is only visible for new records. Records will need to be repeatedly
accessed after they have been entered and I need to make it quick and easy
for users to do this simply by searching for the combo number.

Also, I'm sorry, but coding is rather foreign to me. When I go to enter the
code for the unbound combo box in the After Update, the VBA window opens and
there is a bunch of code in there already...I'm lost as to where to put this
new code. And should "TableName" be the name of the table I'm storing the
info in (tblRPALog)? Is that the only code I need to replace with my
information? Whatever I'm doing, it's not working.

When you say in the Form current event, do you mean to click that little box
in the upper left corner to select the whole form and put the code in the
current event of that? Again, where, when the window opens, do I put the code.

Klatuu said:
Notice the code for the form current event. That makes the the combo visible
for new records.

Then when the combo is made visible and the user selects a division, the
number is assigned and the bound controls are populated.

As to two fields compared to one combined field. Using two fields provides
more flexibility and make coding easier. Don't confuse what is carried in
the database with what is presented visually to the user. The user will see
both values. You can position the controls so the user sees the division and
number together.

The user has to select a division before a number can be created.
--
Dave Hargis, Microsoft Access MVP


bbypookins said:
The user needs to be able to quickly and easily access the record based on
that combined number. How would they do the field is not visible on the form
and is not logged in the table as one combined field?

Klatuu said:
You will need an unbound control on your Access Form to select the division.
I would use a combo box. In your table, I would use 2 fields - one for the
Division and one for the number. In the After Update event of the combo box,
determine the current highest number for the selected division and add one
to it. Also, I would make this combo box invisible except for new records.

Private Sub cboDivisonSelect_AfterUpdate()

Me.txtDivision = Me.cboDivisionSelect
Me.txtSeqNumber = Nz(DLookup("[SeqNumber]", "TableName", "[Division] =
""" & Me.cboDivisionSelect & """"), 0) + 1

End Sub

Now in the Form Current Event:

With Me
If .NewRecord Then
.cboDivisionSelect.Visible = True
.cboDivisionSelect.SetFocus
Else
.cboDivisionSelect.Visible = False
End If

End Sub
--
Dave Hargis, Microsoft Access MVP


:

I'm talking about a hard copy form we that comes into our office. I'm
creating a database to log these forms.

:

I don't think you receive forms. Forms do not contain any data. Data is
contained in tables. Forms are used to present and manipulate data.
What are you actually receiving?
--
Dave Hargis, Microsoft Access MVP


:

I'm creating a database to track a particular form that we receive in our
office. When we receive the form we give it a unique number that combines the
division it came from and a sequential number pertaining to that division
only. In other words, when a form comes in from Executive, it will be given
the number EXE-001 and the next time one form Executive comes in it will be
EXE-002, and so on. When one from Finance & Administration comes in it will
be numbered FA-001, then FA-002, etc.

What I'd like to be able to do in the form is have a combo box field to
select the division from qryDivision and then have the sequential number be
generated automatically depending on what division you choose. Then, I'd like
those two fields to be combined in one field (RPA_No) in the main table
(tblRPALog).

I have no idea how to do this and I'm easily confused when it comes to coding.
 
K

Klatuu

When you want to put code in an event for a form or any controls on the form,
open the form in design view.
Select the form or the control you want to add the code to. Open the
properties dialog and select the Events tab.
Select the event you want to add code to and click the small command button
with the 3 dots. If there is already code in the event, the VB editor will
open showing the existing event code. If there is no code for the event, you
will get a dialog box. Select Code Builder. The VB editor will open, but
there will be no code in the event. All you will see is the declaration of
the event name and the line End Sub. For example, lets say you have a combo
box names cboSearch and you want to enter code for the combo's After Update
event. You would see:

Private Sub cboSearch_AfterUpdate()

End Sub

You would then enter the code for the event between these two lines.

Creating a new number and searching for an exiting number are two different
things. The combo I suggested previously would be for selecting the division
code for a new record so it would know which number to increment.

To search for an existing record, you would need another unbound combo that
would allow you to search for a combination of the fields.

Before we take that on, lets get adding a new record working.

As to the names. I don't know what your names are, but you need to change
any names in the code to match the names of your tables, controls, fields,
etc.

You may see existing code, but you need to see what event it relates to. If
there is already code in an event you want to add code to, you need to make
sure the new code doesn't interfer with the existing code.

If you are not that familiar with VBA, I would suggest you visit this site.
There are a lot of examples and tutorials that will help you out:

http://allenbrowne.com/

--
Dave Hargis, Microsoft Access MVP


bbypookins said:
I'm still confused how one would search for a record based on the combo if
it is only visible for new records. Records will need to be repeatedly
accessed after they have been entered and I need to make it quick and easy
for users to do this simply by searching for the combo number.

Also, I'm sorry, but coding is rather foreign to me. When I go to enter the
code for the unbound combo box in the After Update, the VBA window opens and
there is a bunch of code in there already...I'm lost as to where to put this
new code. And should "TableName" be the name of the table I'm storing the
info in (tblRPALog)? Is that the only code I need to replace with my
information? Whatever I'm doing, it's not working.

When you say in the Form current event, do you mean to click that little box
in the upper left corner to select the whole form and put the code in the
current event of that? Again, where, when the window opens, do I put the code.

Klatuu said:
Notice the code for the form current event. That makes the the combo visible
for new records.

Then when the combo is made visible and the user selects a division, the
number is assigned and the bound controls are populated.

As to two fields compared to one combined field. Using two fields provides
more flexibility and make coding easier. Don't confuse what is carried in
the database with what is presented visually to the user. The user will see
both values. You can position the controls so the user sees the division and
number together.

The user has to select a division before a number can be created.
--
Dave Hargis, Microsoft Access MVP


bbypookins said:
The user needs to be able to quickly and easily access the record based on
that combined number. How would they do the field is not visible on the form
and is not logged in the table as one combined field?

:

You will need an unbound control on your Access Form to select the division.
I would use a combo box. In your table, I would use 2 fields - one for the
Division and one for the number. In the After Update event of the combo box,
determine the current highest number for the selected division and add one
to it. Also, I would make this combo box invisible except for new records.

Private Sub cboDivisonSelect_AfterUpdate()

Me.txtDivision = Me.cboDivisionSelect
Me.txtSeqNumber = Nz(DLookup("[SeqNumber]", "TableName", "[Division] =
""" & Me.cboDivisionSelect & """"), 0) + 1

End Sub

Now in the Form Current Event:

With Me
If .NewRecord Then
.cboDivisionSelect.Visible = True
.cboDivisionSelect.SetFocus
Else
.cboDivisionSelect.Visible = False
End If

End Sub
--
Dave Hargis, Microsoft Access MVP


:

I'm talking about a hard copy form we that comes into our office. I'm
creating a database to log these forms.

:

I don't think you receive forms. Forms do not contain any data. Data is
contained in tables. Forms are used to present and manipulate data.
What are you actually receiving?
--
Dave Hargis, Microsoft Access MVP


:

I'm creating a database to track a particular form that we receive in our
office. When we receive the form we give it a unique number that combines the
division it came from and a sequential number pertaining to that division
only. In other words, when a form comes in from Executive, it will be given
the number EXE-001 and the next time one form Executive comes in it will be
EXE-002, and so on. When one from Finance & Administration comes in it will
be numbered FA-001, then FA-002, etc.

What I'd like to be able to do in the form is have a combo box field to
select the division from qryDivision and then have the sequential number be
generated automatically depending on what division you choose. Then, I'd like
those two fields to be combined in one field (RPA_No) in the main table
(tblRPALog).

I have no idea how to do this and I'm easily confused when it comes to coding.
 
B

bbypookins

I created a combo box, named it RPA_Number (seems to be showing up below as
Combo42). When I go to the After Update and click on the elipse, all the code
below is in the window.

Option Compare Database

Private Sub Combo42_AfterUpdate()

End Sub

Private Sub Division_AfterUpdate()

End Sub

Private Sub RPA__AfterUpdate()

End Sub

Private Sub RPA__Enter()

End Sub
Private Sub NewRecord_Click()
On Error GoTo Err_NewRecord_Click


DoCmd.GoToRecord , , acNewRec

Exit_NewRecord_Click:
Exit Sub

Err_NewRecord_Click:
MsgBox Err.Description
Resume Exit_NewRecord_Click

End Sub
Private Sub PreviousRecord_Click()
On Error GoTo Err_PreviousRecord_Click


DoCmd.GoToRecord , , acPrevious

Exit_PreviousRecord_Click:
Exit Sub

Err_PreviousRecord_Click:
MsgBox Err.Description
Resume Exit_PreviousRecord_Click

End Sub
Private Sub NextRecord_Click()
On Error GoTo Err_NextRecord_Click


DoCmd.GoToRecord , , acNext

Exit_NextRecord_Click:
Exit Sub

Err_NextRecord_Click:
MsgBox Err.Description
Resume Exit_NextRecord_Click

End Sub
Private Sub ExitAccess_Click()
On Error GoTo Err_ExitAccess_Click


DoCmd.Quit

Exit_ExitAccess_Click:
Exit Sub

Err_ExitAccess_Click:
MsgBox Err.Description
Resume Exit_ExitAccess_Click

End Sub

Private Sub RPA_Number_AfterUpdate()

End Sub
 
B

bbypookins

I entered this code for the form current event and when I try to exit it
highlights the first line in yellow with an arrow at the left.

Private Sub Form_Current()
With Me
If .NewRecord Then
.cboRPA_Number.Visible = True
.cboRPA_Number.SetFocus
Else
.cboRPA_Number.Visible = False
End If

End Sub

Klatuu said:
Private Sub cboDivisonSelect_AfterUpdate()

Me.txtDivision = Me.cboDivisionSelect
Me.txtSeqNumber = Nz(DLookup("[SeqNumber]", "TableName", "[Division] =
""" & Me.cboDivisionSelect & """"), 0) + 1

End Sub

Now in the Form Current Event:

With Me
If .NewRecord Then
.cboDivisionSelect.Visible = True
.cboDivisionSelect.SetFocus
Else
.cboDivisionSelect.Visible = False
End If

End Sub
--
Dave Hargis, Microsoft Access MVP


bbypookins said:
I'm talking about a hard copy form we that comes into our office. I'm
creating a database to log these forms.
 
B

bbypookins

Okay, I'm starting from scratch now with a brand new form because I think I
screwed something up in the other one.

At the very beginning, I see what one of my problems was...I had a combo box
bound to qryDivision which was created from the tblDivision. When you say to
create an unbound control to select the division, I'm already confused. In
this new form I've created a combo box called cboDivisionSelect (it's the
only field in my form), but if it's unbound, how do I get the list of
divisions in there to choose from?

Next, you said that I have to replace the names in the code with my names.
Unfortunately, because I'm not too familiar with VBA, I don't know what code
is supposed to be replaced...In the AfterUpdate code I can deduct that
"cboDivisionSelect" is the name of the new unbound combo box, which is
actually the correct name. The only other thing I know I need to change is
"TableName" but is it supposed to be the name of the table the information is
being stored in? Anything else?

I can't thank you enough for your help. I can imagine how annoying this is
getting for you when it would probably take you all of an hour to create the
whole form. I've been working on it (off and on) for months! It would be best
if they would hire someone to create this, but, since I work for the
government, that's not going to happen.


Klatuu said:
You will need an unbound control on your Access Form to select the division.
How do I select
I would use a combo box. In your table, I would use 2 fields - one for the
Division and one for the number. In the After Update event of the combo box,
determine the current highest number for the selected division and add one
to it. Also, I would make this combo box invisible except for new records.

Private Sub cboDivisonSelect_AfterUpdate()

Me.txtDivision = Me.cboDivisionSelect
Me.txtSeqNumber = Nz(DLookup("[SeqNumber]", "TableName", "[Division] =
""" & Me.cboDivisionSelect & """"), 0) + 1

End Sub

Now in the Form Current Event:

With Me
If .NewRecord Then
.cboDivisionSelect.Visible = True
.cboDivisionSelect.SetFocus
Else
.cboDivisionSelect.Visible = False
End If

End Sub
[/QUOTE]
 
B

bbypookins

I've got the current event working! Progress! But, I still can't get the
combo box to work.
Below is the code I have. I'm getting a "Compile error: Method or data
member not found" and it is highlighting ".Division =" of the first
Me.Division line.

Private Sub cboDivisionSelect_AfterUpdate()
Me.Division = Me.cboDivisionSelect
Me.SeqNumber = Nz(DLookup("[SeqNumber]", "tblRPALog", "[Division] = """
& Me.cboDivisionSelect & """"), 0) + 1
End Sub




Klatuu said:
When you want to put code in an event for a form or any controls on the form,
open the form in design view.
Select the form or the control you want to add the code to. Open the
properties dialog and select the Events tab.
Select the event you want to add code to and click the small command button
with the 3 dots. If there is already code in the event, the VB editor will
open showing the existing event code. If there is no code for the event, you
will get a dialog box. Select Code Builder. The VB editor will open, but
there will be no code in the event. All you will see is the declaration of
the event name and the line End Sub. For example, lets say you have a combo
box names cboSearch and you want to enter code for the combo's After Update
event. You would see:

Private Sub cboSearch_AfterUpdate()

End Sub

You would then enter the code for the event between these two lines.

Creating a new number and searching for an exiting number are two different
things. The combo I suggested previously would be for selecting the division
code for a new record so it would know which number to increment.

To search for an existing record, you would need another unbound combo that
would allow you to search for a combination of the fields.

Before we take that on, lets get adding a new record working.

As to the names. I don't know what your names are, but you need to change
any names in the code to match the names of your tables, controls, fields,
etc.

You may see existing code, but you need to see what event it relates to. If
there is already code in an event you want to add code to, you need to make
sure the new code doesn't interfer with the existing code.

If you are not that familiar with VBA, I would suggest you visit this site.
There are a lot of examples and tutorials that will help you out:

http://allenbrowne.com/

--
Dave Hargis, Microsoft Access MVP


bbypookins said:
I'm still confused how one would search for a record based on the combo if
it is only visible for new records. Records will need to be repeatedly
accessed after they have been entered and I need to make it quick and easy
for users to do this simply by searching for the combo number.

Also, I'm sorry, but coding is rather foreign to me. When I go to enter the
code for the unbound combo box in the After Update, the VBA window opens and
there is a bunch of code in there already...I'm lost as to where to put this
new code. And should "TableName" be the name of the table I'm storing the
info in (tblRPALog)? Is that the only code I need to replace with my
information? Whatever I'm doing, it's not working.

When you say in the Form current event, do you mean to click that little box
in the upper left corner to select the whole form and put the code in the
current event of that? Again, where, when the window opens, do I put the code.

Klatuu said:
Notice the code for the form current event. That makes the the combo visible
for new records.

Then when the combo is made visible and the user selects a division, the
number is assigned and the bound controls are populated.

As to two fields compared to one combined field. Using two fields provides
more flexibility and make coding easier. Don't confuse what is carried in
the database with what is presented visually to the user. The user will see
both values. You can position the controls so the user sees the division and
number together.

The user has to select a division before a number can be created.
--
Dave Hargis, Microsoft Access MVP


:

The user needs to be able to quickly and easily access the record based on
that combined number. How would they do the field is not visible on the form
and is not logged in the table as one combined field?

:

You will need an unbound control on your Access Form to select the division.
I would use a combo box. In your table, I would use 2 fields - one for the
Division and one for the number. In the After Update event of the combo box,
determine the current highest number for the selected division and add one
to it. Also, I would make this combo box invisible except for new records.

Private Sub cboDivisonSelect_AfterUpdate()

Me.txtDivision = Me.cboDivisionSelect
Me.txtSeqNumber = Nz(DLookup("[SeqNumber]", "TableName", "[Division] =
""" & Me.cboDivisionSelect & """"), 0) + 1

End Sub

Now in the Form Current Event:

With Me
If .NewRecord Then
.cboDivisionSelect.Visible = True
.cboDivisionSelect.SetFocus
Else
.cboDivisionSelect.Visible = False
End If

End Sub
--
Dave Hargis, Microsoft Access MVP


:

I'm talking about a hard copy form we that comes into our office. I'm
creating a database to log these forms.

:

I don't think you receive forms. Forms do not contain any data. Data is
contained in tables. Forms are used to present and manipulate data.
What are you actually receiving?
--
Dave Hargis, Microsoft Access MVP


:

I'm creating a database to track a particular form that we receive in our
office. When we receive the form we give it a unique number that combines the
division it came from and a sequential number pertaining to that division
only. In other words, when a form comes in from Executive, it will be given
the number EXE-001 and the next time one form Executive comes in it will be
EXE-002, and so on. When one from Finance & Administration comes in it will
be numbered FA-001, then FA-002, etc.

What I'd like to be able to do in the form is have a combo box field to
select the division from qryDivision and then have the sequential number be
generated automatically depending on what division you choose. Then, I'd like
those two fields to be combined in one field (RPA_No) in the main table
(tblRPALog).

I have no idea how to do this and I'm easily confused when it comes to coding.
 

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