RE: Blank fields when adding new record to combo box

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



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" wrote:

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" wrote:

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" wrote:

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!

.



Relevant Pages

  • Re: page fault in igb driver on 8.0-RC2
    ... <Enhanced SpeedStep Frequency Control> on cpu0 ... vendor = 'Intel Corporation' ... subclass = interrupt controller ...
    (freebsd-current)
  • RE: Blank fields when adding new record to combo box
    ... StartDate = StartDate ... Dave Hargis, Microsoft Access MVP ... you need to requery the combo so it has the new vendor in the ... Private Sub Combo35_NotInList ...
    (microsoft.public.access.formscoding)
  • RE: Blank fields when adding new record to combo box
    ... Dave Hargis, Microsoft Access MVP ... StartDate = StartDate ... you need to requery the combo so it has the new vendor in the ... Private Sub Combo35_NotInList ...
    (microsoft.public.access.formscoding)
  • Re: A form, query and table
    ... My form is based on three things: vendor name, ... You put Controls on a form, usually one control bound to each field that you ... You are talking about "Table1 is dumped into ComboBox1". ... the Recordsource of your form should be Table4; ...
    (microsoft.public.access.gettingstarted)
  • RE: Blank fields when adding new record to combo box
    ... You need to requery the combo so the new vendor will be included in the ... Dave Hargis, Microsoft Access MVP ... StartDate = StartDate ... Private Sub Combo35_NotInList ...
    (microsoft.public.access.formscoding)