Home > Software engineering >  Getting #Name? error in combobox - MS Access
Getting #Name? error in combobox - MS Access

Time:06-04

I'm trying to set the default value of a few items on my form so I don't have to keep updating them as I scan items to a table. I have 3 comboboxes in my form and the other two are working fine (keeping the same value after record entry) but the cbx for "Equipment" is consistently giving me this error. I've tried updating field names by going from "Type" to "Equipment Type" and now to "Equipment" and that has not fixed it. I'll try to give good context below, but please let me know if there is more information you need. Thanks! --Forgot to mention that the table for equipment types has one field: "EQType" and it is set as the primary key.

VBA to set default values in comboboxes

Private Sub Serial_Number_AfterUpdate()

[Equipment].DefaultValue = [Equipment]
[ToTech].DefaultValue = [ToTech]
[FromTech].DefaultValue = [FromTech]

End Sub

Field names of the table I'm updating:

  • Serial Number (Textbox)
    • Control source: Serial Number
  • Equipment (Combobox)
    • Control source: Equipment
    • Row Source: SELECT EQType FROM EquipmentTypes;
  • From Tech (Combobox)
    • Row Source: SELECT Roster.TechID FROM Roster;
  • To Tech (Combobox)
    • Row Source: SELECT Roster.TechID FROM Roster;
  • Date Added (Textbox) --Default Value set to "=Date()"

Information about form:

Split form, named "Transfers", Record Source = Transfers table

CodePudding user response:

DefaultValue is text, so you probably miss to quote the value:

Private Sub Serial_Number_AfterUpdate()

    Me![Equipment].DefaultValue = "'" & Me![Equipment].Value & "'"
    Me![ToTech].DefaultValue = Me![ToTech].Value
    Me![FromTech].DefaultValue = Me![FromTech].Value

End Sub
  • Related