Blank fields when adding new record to combo box

G

Guest

I have created a form that uses data from the Vendors tbl (Vendor Name) and
the Contracts tbl (Project Name, number, etc.). The user can add a new vendor
in the form with the combo box however; when I save the new record and open
the Contracts tbl, the new Vendor name field is blank. Can someone please
review the code that I used below to help me identify what's wrong?

Private Sub Combo35_NotInList(NewData As String, Response As Integer)
Dim Result
Dim Msg As String
' Exit this subroutine if the combo box was cleared.
If NewData = "" Then Exit Sub

'Ask the user it they wish to add the new vendor.
Msg = "'" & NewData & "' is not in the list."
Msg = Msg & "Do you want to add it?"
If MsgBox(Msg, vbQuestion + vbYesNo) = vbYes Then
'If the user chose Yes, start the Vendors form in data entry mode
'as a dialog form, passing the new vendor name in NewData to the
'OpenForm method's OpenArgs argument. The OpenArgs argument is used in
'Vendors form's Form_Load event procedure.
DoCmd.OpenForm "frmAddVendors", , , , acFormAdd, acDialog, NewData
Combo35.SetFocus
Response = acDataErrAdded
End If
End Sub

Vendor Form on Load event
Private Sub Form_Load()

If Not IsNull(Me.OpenArgs) Then
Me![Vendor Name] = Me.OpenArgs
End If

End Sub

Any assistance is greatly appreciated!
 
G

Guest

First, is your combo bound to the vendor name field?
Second, you need to requery the combo so it has the new vendor in the
combo's list. Then, you need to be sure the new vendor is the one selected:

'Vendors form's Form_Load event procedure.
DoCmd.OpenForm "frmAddVendors", , , , acFormAdd, acDialog, NewData
Me.Combo35.Requery
Me.Combo35 = NewDAta
Response = acDataErrAdded

Note, it is a very good idea to qualify your objects. It makes it easier
for we human types and for Access to know who we are talking about.
 
G

Guest

The combo is unbound. As my name implies I a very new at Access so can you be
more specific with your note to "qualify objects".

Klatuu said:
First, is your combo bound to the vendor name field?
Second, you need to requery the combo so it has the new vendor in the
combo's list. Then, you need to be sure the new vendor is the one selected:

'Vendors form's Form_Load event procedure.
DoCmd.OpenForm "frmAddVendors", , , , acFormAdd, acDialog, NewData
Me.Combo35.Requery
Me.Combo35 = NewDAta
Response = acDataErrAdded

Note, it is a very good idea to qualify your objects. It makes it easier
for we human types and for Access to know who we are talking about.

--
Dave Hargis, Microsoft Access MVP


babysteps said:
I have created a form that uses data from the Vendors tbl (Vendor Name) and
the Contracts tbl (Project Name, number, etc.). The user can add a new vendor
in the form with the combo box however; when I save the new record and open
the Contracts tbl, the new Vendor name field is blank. Can someone please
review the code that I used below to help me identify what's wrong?

Private Sub Combo35_NotInList(NewData As String, Response As Integer)
Dim Result
Dim Msg As String
' Exit this subroutine if the combo box was cleared.
If NewData = "" Then Exit Sub

'Ask the user it they wish to add the new vendor.
Msg = "'" & NewData & "' is not in the list."
Msg = Msg & "Do you want to add it?"
If MsgBox(Msg, vbQuestion + vbYesNo) = vbYes Then
'If the user chose Yes, start the Vendors form in data entry mode
'as a dialog form, passing the new vendor name in NewData to the
'OpenForm method's OpenArgs argument. The OpenArgs argument is used in
'Vendors form's Form_Load event procedure.
DoCmd.OpenForm "frmAddVendors", , , , acFormAdd, acDialog, NewData
Combo35.SetFocus
Response = acDataErrAdded
End If
End Sub

Vendor Form on Load event
Private Sub Form_Load()

If Not IsNull(Me.OpenArgs) Then
Me![Vendor Name] = Me.OpenArgs
End If

End Sub

Any assistance is greatly appreciated!
 
G

Guest

sure.

If you have a control on your form named Frodo, the correct syntax is

Me.Frodo = Date

The Me is a shortcut that can be use to substitute for the explicit
Forms!MyFormName


So either

Forms!MyFormName!Frodo

or

Me.Frodo

or Me!Frodo

In reality, the ! is the correct syntax; however, you will find a lot of
people using the . because it provided the intellisense assistance. That is
when you are in the VBA editor and coding in a form or report module and type
in Me. You get a drop down with a list of all the properties and methods
associated with the form.

Improper qualification can confuse Access. It certainly confuses we humans.
For example, what would you make of this:

StartDate = StartDate

What is the world are we talking about here? Which StartDate? How many
StartDates do I have. Because people will use the form wizard to create a
form, it comes out with the control name being exactly the same as the Field
name it is bound to. (I wish MS would not do that). So, one is likely a
field in the form's record source and the other is the control, or is it we
have a variable named StartDate.

These issues can be solved using two basic techniques.
First, qualify the objects, methods, and properties.
Second, use good naming conventions so you know immediately by reading the
name what it is.

Here is a site that has some good info on naming:
http://msdn.microsoft.com/archive/default.asp?url=/archive/en-us/dnaraccess/html/msdn_20naming.asp

you will find that for Access objects, most use a prefix to determine what
the object is:

Form - frm
Report - rpt
Table = tbl
Text Box = txt
Combo Box = cbo
List Box = lst
Check Box = chk
Image control = img
Command Button = cmd
Option Group = opg

For variable types (It makes it easy to know exactly what you can and can't
do with a variable, particularly if you are reading another's code):

String = str
Integer = int
Long = lng
Single = sng
Double = dbl
Date = dtm
Boolean = bln

Not a complete list, but enough to get the idea. So, back to the original
example:

Me.txtStartDate = dtmStartDate

Now we know we have a date/time variable name dtmStartDate and we are using
its value to populate a text box control on the current form named
txtStartDate.

Hope this will help you. It may seem a bit of overkill now, but come back
and look at the code 6 months from now and see if you can still understand it.
--
Dave Hargis, Microsoft Access MVP


babysteps said:
The combo is unbound. As my name implies I a very new at Access so can you be
more specific with your note to "qualify objects".

Klatuu said:
First, is your combo bound to the vendor name field?
Second, you need to requery the combo so it has the new vendor in the
combo's list. Then, you need to be sure the new vendor is the one selected:

'Vendors form's Form_Load event procedure.
DoCmd.OpenForm "frmAddVendors", , , , acFormAdd, acDialog, NewData
Me.Combo35.Requery
Me.Combo35 = NewDAta
Response = acDataErrAdded

Note, it is a very good idea to qualify your objects. It makes it easier
for we human types and for Access to know who we are talking about.

--
Dave Hargis, Microsoft Access MVP


babysteps said:
I have created a form that uses data from the Vendors tbl (Vendor Name) and
the Contracts tbl (Project Name, number, etc.). The user can add a new vendor
in the form with the combo box however; when I save the new record and open
the Contracts tbl, the new Vendor name field is blank. Can someone please
review the code that I used below to help me identify what's wrong?

Private Sub Combo35_NotInList(NewData As String, Response As Integer)
Dim Result
Dim Msg As String
' Exit this subroutine if the combo box was cleared.
If NewData = "" Then Exit Sub

'Ask the user it they wish to add the new vendor.
Msg = "'" & NewData & "' is not in the list."
Msg = Msg & "Do you want to add it?"
If MsgBox(Msg, vbQuestion + vbYesNo) = vbYes Then
'If the user chose Yes, start the Vendors form in data entry mode
'as a dialog form, passing the new vendor name in NewData to the
'OpenForm method's OpenArgs argument. The OpenArgs argument is used in
'Vendors form's Form_Load event procedure.
DoCmd.OpenForm "frmAddVendors", , , , acFormAdd, acDialog, NewData
Combo35.SetFocus
Response = acDataErrAdded
End If
End Sub

Vendor Form on Load event
Private Sub Form_Load()

If Not IsNull(Me.OpenArgs) Then
Me![Vendor Name] = Me.OpenArgs
End If

End Sub

Any assistance is greatly appreciated!
 
G

Guest

:

I will visit the site you listed to make sure that I am using the correct
naming conventions going forward. Does my answer about the combo box being
unbound help in any way to identify the blank field in my record?

Klatuu said:
sure.

If you have a control on your form named Frodo, the correct syntax is

Me.Frodo = Date

The Me is a shortcut that can be use to substitute for the explicit
Forms!MyFormName


So either

Forms!MyFormName!Frodo

or

Me.Frodo

or Me!Frodo

In reality, the ! is the correct syntax; however, you will find a lot of
people using the . because it provided the intellisense assistance. That is
when you are in the VBA editor and coding in a form or report module and type
in Me. You get a drop down with a list of all the properties and methods
associated with the form.

Improper qualification can confuse Access. It certainly confuses we humans.
For example, what would you make of this:

StartDate = StartDate

What is the world are we talking about here? Which StartDate? How many
StartDates do I have. Because people will use the form wizard to create a
form, it comes out with the control name being exactly the same as the Field
name it is bound to. (I wish MS would not do that). So, one is likely a
field in the form's record source and the other is the control, or is it we
have a variable named StartDate.

These issues can be solved using two basic techniques.
First, qualify the objects, methods, and properties.
Second, use good naming conventions so you know immediately by reading the
name what it is.

Here is a site that has some good info on naming:
http://msdn.microsoft.com/archive/default.asp?url=/archive/en-us/dnaraccess/html/msdn_20naming.asp

you will find that for Access objects, most use a prefix to determine what
the object is:

Form - frm
Report - rpt
Table = tbl
Text Box = txt
Combo Box = cbo
List Box = lst
Check Box = chk
Image control = img
Command Button = cmd
Option Group = opg

For variable types (It makes it easy to know exactly what you can and can't
do with a variable, particularly if you are reading another's code):

String = str
Integer = int
Long = lng
Single = sng
Double = dbl
Date = dtm
Boolean = bln

Not a complete list, but enough to get the idea. So, back to the original
example:

Me.txtStartDate = dtmStartDate

Now we know we have a date/time variable name dtmStartDate and we are using
its value to populate a text box control on the current form named
txtStartDate.

Hope this will help you. It may seem a bit of overkill now, but come back
and look at the code 6 months from now and see if you can still understand it.
--
Dave Hargis, Microsoft Access MVP


babysteps said:
The combo is unbound. As my name implies I a very new at Access so can you be
more specific with your note to "qualify objects".

Klatuu said:
First, is your combo bound to the vendor name field?
Second, you need to requery the combo so it has the new vendor in the
combo's list. Then, you need to be sure the new vendor is the one selected:

'Vendors form's Form_Load event procedure.
DoCmd.OpenForm "frmAddVendors", , , , acFormAdd, acDialog, NewData
Me.Combo35.Requery
Me.Combo35 = NewDAta
Response = acDataErrAdded

Note, it is a very good idea to qualify your objects. It makes it easier
for we human types and for Access to know who we are talking about.

--
Dave Hargis, Microsoft Access MVP


:

I have created a form that uses data from the Vendors tbl (Vendor Name) and
the Contracts tbl (Project Name, number, etc.). The user can add a new vendor
in the form with the combo box however; when I save the new record and open
the Contracts tbl, the new Vendor name field is blank. Can someone please
review the code that I used below to help me identify what's wrong?

Private Sub Combo35_NotInList(NewData As String, Response As Integer)
Dim Result
Dim Msg As String
' Exit this subroutine if the combo box was cleared.
If NewData = "" Then Exit Sub

'Ask the user it they wish to add the new vendor.
Msg = "'" & NewData & "' is not in the list."
Msg = Msg & "Do you want to add it?"
If MsgBox(Msg, vbQuestion + vbYesNo) = vbYes Then
'If the user chose Yes, start the Vendors form in data entry mode
'as a dialog form, passing the new vendor name in NewData to the
'OpenForm method's OpenArgs argument. The OpenArgs argument is used in
'Vendors form's Form_Load event procedure.
DoCmd.OpenForm "frmAddVendors", , , , acFormAdd, acDialog, NewData
Combo35.SetFocus
Response = acDataErrAdded
End If
End Sub

Vendor Form on Load event
Private Sub Form_Load()

If Not IsNull(Me.OpenArgs) Then
Me![Vendor Name] = Me.OpenArgs
End If

End Sub

Any assistance is greatly appreciated!
 
G

Guest

You need to requery the combo so the new vendor will be included in the
combo's row source. But, sinse a requery moves you back to the first record,
you will need to reposition it to the new record. See if this helps:

DoCmd.OpenForm "frmAddVendors", , , , acFormAdd, acDialog, NewData
Me.Combo35.Requery
Me.Combo35 = NewData
Response = acDataErrAdded

--
Dave Hargis, Microsoft Access MVP


babysteps said:
:

I will visit the site you listed to make sure that I am using the correct
naming conventions going forward. Does my answer about the combo box being
unbound help in any way to identify the blank field in my record?

Klatuu said:
sure.

If you have a control on your form named Frodo, the correct syntax is

Me.Frodo = Date

The Me is a shortcut that can be use to substitute for the explicit
Forms!MyFormName


So either

Forms!MyFormName!Frodo

or

Me.Frodo

or Me!Frodo

In reality, the ! is the correct syntax; however, you will find a lot of
people using the . because it provided the intellisense assistance. That is
when you are in the VBA editor and coding in a form or report module and type
in Me. You get a drop down with a list of all the properties and methods
associated with the form.

Improper qualification can confuse Access. It certainly confuses we humans.
For example, what would you make of this:

StartDate = StartDate

What is the world are we talking about here? Which StartDate? How many
StartDates do I have. Because people will use the form wizard to create a
form, it comes out with the control name being exactly the same as the Field
name it is bound to. (I wish MS would not do that). So, one is likely a
field in the form's record source and the other is the control, or is it we
have a variable named StartDate.

These issues can be solved using two basic techniques.
First, qualify the objects, methods, and properties.
Second, use good naming conventions so you know immediately by reading the
name what it is.

Here is a site that has some good info on naming:
http://msdn.microsoft.com/archive/default.asp?url=/archive/en-us/dnaraccess/html/msdn_20naming.asp

you will find that for Access objects, most use a prefix to determine what
the object is:

Form - frm
Report - rpt
Table = tbl
Text Box = txt
Combo Box = cbo
List Box = lst
Check Box = chk
Image control = img
Command Button = cmd
Option Group = opg

For variable types (It makes it easy to know exactly what you can and can't
do with a variable, particularly if you are reading another's code):

String = str
Integer = int
Long = lng
Single = sng
Double = dbl
Date = dtm
Boolean = bln

Not a complete list, but enough to get the idea. So, back to the original
example:

Me.txtStartDate = dtmStartDate

Now we know we have a date/time variable name dtmStartDate and we are using
its value to populate a text box control on the current form named
txtStartDate.

Hope this will help you. It may seem a bit of overkill now, but come back
and look at the code 6 months from now and see if you can still understand it.
--
Dave Hargis, Microsoft Access MVP


babysteps said:
The combo is unbound. As my name implies I a very new at Access so can you be
more specific with your note to "qualify objects".

:

First, is your combo bound to the vendor name field?
Second, you need to requery the combo so it has the new vendor in the
combo's list. Then, you need to be sure the new vendor is the one selected:

'Vendors form's Form_Load event procedure.
DoCmd.OpenForm "frmAddVendors", , , , acFormAdd, acDialog, NewData
Me.Combo35.Requery
Me.Combo35 = NewDAta
Response = acDataErrAdded

Note, it is a very good idea to qualify your objects. It makes it easier
for we human types and for Access to know who we are talking about.

--
Dave Hargis, Microsoft Access MVP


:

I have created a form that uses data from the Vendors tbl (Vendor Name) and
the Contracts tbl (Project Name, number, etc.). The user can add a new vendor
in the form with the combo box however; when I save the new record and open
the Contracts tbl, the new Vendor name field is blank. Can someone please
review the code that I used below to help me identify what's wrong?

Private Sub Combo35_NotInList(NewData As String, Response As Integer)
Dim Result
Dim Msg As String
' Exit this subroutine if the combo box was cleared.
If NewData = "" Then Exit Sub

'Ask the user it they wish to add the new vendor.
Msg = "'" & NewData & "' is not in the list."
Msg = Msg & "Do you want to add it?"
If MsgBox(Msg, vbQuestion + vbYesNo) = vbYes Then
'If the user chose Yes, start the Vendors form in data entry mode
'as a dialog form, passing the new vendor name in NewData to the
'OpenForm method's OpenArgs argument. The OpenArgs argument is used in
'Vendors form's Form_Load event procedure.
DoCmd.OpenForm "frmAddVendors", , , , acFormAdd, acDialog, NewData
Combo35.SetFocus
Response = acDataErrAdded
End If
End Sub

Vendor Form on Load event
Private Sub Form_Load()

If Not IsNull(Me.OpenArgs) Then
Me![Vendor Name] = Me.OpenArgs
End If

End Sub

Any assistance is greatly appreciated!
 
G

Guest

Adding the requery line gave me the "runtime error 2118" that I should save
the record first. On the frmAddVendors, there is a Save button that the user
clicks before the form closes. I looked up the post regarding the runtime
error and tried moving the save and requery actions to the "On Activate"
event in the form. This ended with the same result of saving the new contract
record without the new vendor name. Any other suggestions?

Klatuu said:
You need to requery the combo so the new vendor will be included in the
combo's row source. But, sinse a requery moves you back to the first record,
you will need to reposition it to the new record. See if this helps:

DoCmd.OpenForm "frmAddVendors", , , , acFormAdd, acDialog, NewData
Me.Combo35.Requery
Me.Combo35 = NewData
Response = acDataErrAdded

--
Dave Hargis, Microsoft Access MVP


babysteps said:
:

I will visit the site you listed to make sure that I am using the correct
naming conventions going forward. Does my answer about the combo box being
unbound help in any way to identify the blank field in my record?

Klatuu said:
sure.

If you have a control on your form named Frodo, the correct syntax is

Me.Frodo = Date

The Me is a shortcut that can be use to substitute for the explicit
Forms!MyFormName


So either

Forms!MyFormName!Frodo

or

Me.Frodo

or Me!Frodo

In reality, the ! is the correct syntax; however, you will find a lot of
people using the . because it provided the intellisense assistance. That is
when you are in the VBA editor and coding in a form or report module and type
in Me. You get a drop down with a list of all the properties and methods
associated with the form.

Improper qualification can confuse Access. It certainly confuses we humans.
For example, what would you make of this:

StartDate = StartDate

What is the world are we talking about here? Which StartDate? How many
StartDates do I have. Because people will use the form wizard to create a
form, it comes out with the control name being exactly the same as the Field
name it is bound to. (I wish MS would not do that). So, one is likely a
field in the form's record source and the other is the control, or is it we
have a variable named StartDate.

These issues can be solved using two basic techniques.
First, qualify the objects, methods, and properties.
Second, use good naming conventions so you know immediately by reading the
name what it is.

Here is a site that has some good info on naming:
http://msdn.microsoft.com/archive/default.asp?url=/archive/en-us/dnaraccess/html/msdn_20naming.asp

you will find that for Access objects, most use a prefix to determine what
the object is:

Form - frm
Report - rpt
Table = tbl
Text Box = txt
Combo Box = cbo
List Box = lst
Check Box = chk
Image control = img
Command Button = cmd
Option Group = opg

For variable types (It makes it easy to know exactly what you can and can't
do with a variable, particularly if you are reading another's code):

String = str
Integer = int
Long = lng
Single = sng
Double = dbl
Date = dtm
Boolean = bln

Not a complete list, but enough to get the idea. So, back to the original
example:

Me.txtStartDate = dtmStartDate

Now we know we have a date/time variable name dtmStartDate and we are using
its value to populate a text box control on the current form named
txtStartDate.

Hope this will help you. It may seem a bit of overkill now, but come back
and look at the code 6 months from now and see if you can still understand it.
--
Dave Hargis, Microsoft Access MVP


:

The combo is unbound. As my name implies I a very new at Access so can you be
more specific with your note to "qualify objects".

:

First, is your combo bound to the vendor name field?
Second, you need to requery the combo so it has the new vendor in the
combo's list. Then, you need to be sure the new vendor is the one selected:

'Vendors form's Form_Load event procedure.
DoCmd.OpenForm "frmAddVendors", , , , acFormAdd, acDialog, NewData
Me.Combo35.Requery
Me.Combo35 = NewDAta
Response = acDataErrAdded

Note, it is a very good idea to qualify your objects. It makes it easier
for we human types and for Access to know who we are talking about.

--
Dave Hargis, Microsoft Access MVP


:

I have created a form that uses data from the Vendors tbl (Vendor Name) and
the Contracts tbl (Project Name, number, etc.). The user can add a new vendor
in the form with the combo box however; when I save the new record and open
the Contracts tbl, the new Vendor name field is blank. Can someone please
review the code that I used below to help me identify what's wrong?

Private Sub Combo35_NotInList(NewData As String, Response As Integer)
Dim Result
Dim Msg As String
' Exit this subroutine if the combo box was cleared.
If NewData = "" Then Exit Sub

'Ask the user it they wish to add the new vendor.
Msg = "'" & NewData & "' is not in the list."
Msg = Msg & "Do you want to add it?"
If MsgBox(Msg, vbQuestion + vbYesNo) = vbYes Then
'If the user chose Yes, start the Vendors form in data entry mode
'as a dialog form, passing the new vendor name in NewData to the
'OpenForm method's OpenArgs argument. The OpenArgs argument is used in
'Vendors form's Form_Load event procedure.
DoCmd.OpenForm "frmAddVendors", , , , acFormAdd, acDialog, NewData
Combo35.SetFocus
Response = acDataErrAdded
End If
End Sub

Vendor Form on Load event
Private Sub Form_Load()

If Not IsNull(Me.OpenArgs) Then
Me![Vendor Name] = Me.OpenArgs
End If

End Sub

Any assistance is greatly appreciated!
 
G

Guest

The Form Activate event would not be the correct place to do that. This is a
bit unusual because when you close a form, the record is saved to the table
unless you explicitly prevent the update.
--
Dave Hargis, Microsoft Access MVP


babysteps said:
Adding the requery line gave me the "runtime error 2118" that I should save
the record first. On the frmAddVendors, there is a Save button that the user
clicks before the form closes. I looked up the post regarding the runtime
error and tried moving the save and requery actions to the "On Activate"
event in the form. This ended with the same result of saving the new contract
record without the new vendor name. Any other suggestions?

Klatuu said:
You need to requery the combo so the new vendor will be included in the
combo's row source. But, sinse a requery moves you back to the first record,
you will need to reposition it to the new record. See if this helps:

DoCmd.OpenForm "frmAddVendors", , , , acFormAdd, acDialog, NewData
Me.Combo35.Requery
Me.Combo35 = NewData
Response = acDataErrAdded

--
Dave Hargis, Microsoft Access MVP


babysteps said:
:

I will visit the site you listed to make sure that I am using the correct
naming conventions going forward. Does my answer about the combo box being
unbound help in any way to identify the blank field in my record?

:

sure.

If you have a control on your form named Frodo, the correct syntax is

Me.Frodo = Date

The Me is a shortcut that can be use to substitute for the explicit
Forms!MyFormName


So either

Forms!MyFormName!Frodo

or

Me.Frodo

or Me!Frodo

In reality, the ! is the correct syntax; however, you will find a lot of
people using the . because it provided the intellisense assistance. That is
when you are in the VBA editor and coding in a form or report module and type
in Me. You get a drop down with a list of all the properties and methods
associated with the form.

Improper qualification can confuse Access. It certainly confuses we humans.
For example, what would you make of this:

StartDate = StartDate

What is the world are we talking about here? Which StartDate? How many
StartDates do I have. Because people will use the form wizard to create a
form, it comes out with the control name being exactly the same as the Field
name it is bound to. (I wish MS would not do that). So, one is likely a
field in the form's record source and the other is the control, or is it we
have a variable named StartDate.

These issues can be solved using two basic techniques.
First, qualify the objects, methods, and properties.
Second, use good naming conventions so you know immediately by reading the
name what it is.

Here is a site that has some good info on naming:
http://msdn.microsoft.com/archive/default.asp?url=/archive/en-us/dnaraccess/html/msdn_20naming.asp

you will find that for Access objects, most use a prefix to determine what
the object is:

Form - frm
Report - rpt
Table = tbl
Text Box = txt
Combo Box = cbo
List Box = lst
Check Box = chk
Image control = img
Command Button = cmd
Option Group = opg

For variable types (It makes it easy to know exactly what you can and can't
do with a variable, particularly if you are reading another's code):

String = str
Integer = int
Long = lng
Single = sng
Double = dbl
Date = dtm
Boolean = bln

Not a complete list, but enough to get the idea. So, back to the original
example:

Me.txtStartDate = dtmStartDate

Now we know we have a date/time variable name dtmStartDate and we are using
its value to populate a text box control on the current form named
txtStartDate.

Hope this will help you. It may seem a bit of overkill now, but come back
and look at the code 6 months from now and see if you can still understand it.
--
Dave Hargis, Microsoft Access MVP


:

The combo is unbound. As my name implies I a very new at Access so can you be
more specific with your note to "qualify objects".

:

First, is your combo bound to the vendor name field?
Second, you need to requery the combo so it has the new vendor in the
combo's list. Then, you need to be sure the new vendor is the one selected:

'Vendors form's Form_Load event procedure.
DoCmd.OpenForm "frmAddVendors", , , , acFormAdd, acDialog, NewData
Me.Combo35.Requery
Me.Combo35 = NewDAta
Response = acDataErrAdded

Note, it is a very good idea to qualify your objects. It makes it easier
for we human types and for Access to know who we are talking about.

--
Dave Hargis, Microsoft Access MVP


:

I have created a form that uses data from the Vendors tbl (Vendor Name) and
the Contracts tbl (Project Name, number, etc.). The user can add a new vendor
in the form with the combo box however; when I save the new record and open
the Contracts tbl, the new Vendor name field is blank. Can someone please
review the code that I used below to help me identify what's wrong?

Private Sub Combo35_NotInList(NewData As String, Response As Integer)
Dim Result
Dim Msg As String
' Exit this subroutine if the combo box was cleared.
If NewData = "" Then Exit Sub

'Ask the user it they wish to add the new vendor.
Msg = "'" & NewData & "' is not in the list."
Msg = Msg & "Do you want to add it?"
If MsgBox(Msg, vbQuestion + vbYesNo) = vbYes Then
'If the user chose Yes, start the Vendors form in data entry mode
'as a dialog form, passing the new vendor name in NewData to the
'OpenForm method's OpenArgs argument. The OpenArgs argument is used in
'Vendors form's Form_Load event procedure.
DoCmd.OpenForm "frmAddVendors", , , , acFormAdd, acDialog, NewData
Combo35.SetFocus
Response = acDataErrAdded
End If
End Sub

Vendor Form on Load event
Private Sub Form_Load()

If Not IsNull(Me.OpenArgs) Then
Me![Vendor Name] = Me.OpenArgs
End If

End Sub

Any assistance is greatly appreciated!
 

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

Similar Threads

Add Record with combo box 13
NotInList not firing ? 1
item not found in this collection 1
open args syntax 2
when to refresh form data 9
Message appears twice. 4
Not In List, saving data 3
NotInList Firing Problem 12

Top