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,807
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,081,657
Messages
5,360,291
Members
400,580
Latest member
Drexl88

Some videos you may like

This Week's Hot Topics

  • VBA (Userform)
    Hi All, I just would like to know why my code isn't working. Here is my VBA code: [CODE=vba]Private Sub OKButton_Click() Dim i As Integer...
  • List box that changes fill color
    Hello, I have gone through so many pages trying to figure this out. I have a 2020 calendar that depending on the day needs to have a certain...
  • Remove duplicates and retain one. Cross-linked cases
    Hi all I ran out of google keywords to use and still couldn't find a reference how to achieve the results of a single count. It would be great if...
  • VBA Copy and Paste With Duplicates
    Hello All, I'm in need of some input. My VBA skills are sub-par at best. I've assembled this code from basic research and it works but is...
  • Macro
    is it possible for a macro to run if the active cell value is different to the value above it
  • IF DATE and TIME
    I currently use this to check if date has passed but i also need to set a time on it too. Is it possible? [CODE=vba]=IF(B:B>TODAY(),"Not...
Top