Need help with an access max/dlookup

Buns1976

Board Regular
Joined
Feb 11, 2019
Messages
138
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!!

Code:
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)
Scan.SetFocus
 
Last edited:

ranman256

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

Code:
'----------------
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
Else
  Me.Filter = sWhere
  Me.FilterOn = True
End If
end sub
 

Forum statistics

Threads
1,077,638
Messages
5,335,393
Members
399,015
Latest member
emalabel

Some videos you may like

This Week's Hot Topics

Top