Need help with an access max/dlookup


Board Regular
Feb 11, 2019
Hi Everyone,

I'm an absolute novice at best with Access but am trying to learn.

I am running the code below on a button in a filtered form. What I would like to do is run it after my last field is entered IN THE FIRST RECORD and I press the ENTER key
creating a new record. In addition in the SLOT field of the first record we I enter "1". What I would like it to do is in the 2nd record, be 2, third record 3, etc.

Thanks a bunch!!

Dim ID As Long
ID = DMax("ProductID", "Table1")
DoCmd.GoToRecord , , acNewRec
Slot = DLookup("Slot", "Table1", "ProductID=" & ID)
Associate = DLookup("Associate", "Table1", "ProductID=" & ID)
DateEntered = DLookup("DateEntered", "Table1", "ProductID=" & ID)
Last edited:


Well-known Member
Jun 17, 2014
just show all records, then filter them all at once.
No dlookups needed:

sub btnFilter_click()
dim sWhere as string 
sWhere = "1=1"
if not IsNUll(cboST) then sWhere = sWhere & " and [State]='" & cboST & "'"
if not IsNUll(cboCity) then sWhere = sWhere & " and [city]='" & cboCity & "'"
if not IsNUll(cboZip) then sWhere = sWhere & " and [ZipCode]='" & cboZip & "'"
If sWhere = "1=1" Then
  Me.FilterOn = False
  Me.Filter = sWhere
  Me.FilterOn = True
End If
end sub

Forum statistics

Latest member

Some videos you may like

This Week's Hot Topics

  • populate from drop list with multiple tables
    Hi All, i have a drop list that displays data, what i want is when i select one of those from the list to populate text from different tables on...
  • Find list of words from sheet2 in sheet1 before a comma and extract text vba
    Hi Friends, Trying to find the solution on my task. But did not find suitable one to the need. Here is my query and sample file with details...
  • Dynamic Formula entry - VBA code sought
    Hello, really hope one of you experts can help with this - i've spent hours on this and getting no-where. .I have a set of data (more rows than...
  • Listbox Header
    Have a named range called "AccidentsHeader" Within my code I have: [CODE]Private Sub CommandButton1_Click() ListBox1.RowSource =...
  • Complex Heat Map using conditional formatting
    Good day excel world. I have a concern. Below link have a list of countries that carries each country unique data. [URL...
  • Conditional formatting
    Hi good morning, hope you can help me please, I have cells P4:P54 and if this cell is equal to 1 then i want row O to say "Fully Utilised" and to...