473,657 Members | 2,530 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

DMax function

Hello,

I need to add several new records to Table2 from Table1. Table2
contains a field called [Member Number] that needs to be the previous
maximum value of [Member Number] incremented by 1.

Below is my code but i keep getting the error "MyDatabase " can't find
the field '|' referred to in your expression. Please help, I am going
crazy here :)!

Private Sub cmdNewOnlineMbr _Click()
On Error GoTo Err_cmdNewOnlin eMbr_Click

Dim db As Database ' Current database
Dim rsOnlineDb As Recordset ' Source table
Dim rsInhouseDb As Recordset ' Target table
Dim i As Integer ' Loop counter

DoCmd.OpenQuery "qryAddNewMembe rs"
Set db = CurrentDb()
Set rsOnlineDb = db.OpenRecordse t("Member Updates")
Set rsInhouseDb = db.OpenRecordse t("New Members")
With rsInhouseDb
' Loop through all records in source table.
Do While Not rsOnlineDb.EOF
' Add all new records to target table.
.AddNew
!MEMBERNUMBER = DMax([MEMBER NUMBER], Members) + 1
!FIRST = rsOnlineDb!Firs tName
!MI = rsOnlineDb!MI
!LAST = rsOnlineDb!Last Name
!MBRSHPEXP = rsOnlineDb!MBRS HPEXP
!NOTES = rsOnlineDb!NOTE S
!EMPLOYER = rsOnlineDb!EMPL OYER
!POSITION = rsOnlineDb!Posi tionTitle
!ADDRESS1 = rsOnlineDb!ADDR ESS1
!ADDRESS2 = rsOnlineDb!ADDR ESS2
!ADDRESS3 = rsOnlineDb!ADDR ESS3
.Update
rsOnlineDb.Move Next
Loop
End With
rsInhouseDb.Clo se
rsOnlineDb.Clos e
Exit_cmdNewOnli neMbr_Click:
Exit Sub

Err_cmdNewOnlin eMbr_Click:
MsgBox Err.Description
Resume Exit_cmdNewOnli neMbr_Click

End Sub
Sep 10 '08 #1
1 4775
nr****@gmail.co m wrote:
Hello,

I need to add several new records to Table2 from Table1. Table2
contains a field called [Member Number] that needs to be the previous
maximum value of [Member Number] incremented by 1.

Below is my code but i keep getting the error "MyDatabase " can't find
the field '|' referred to in your expression. Please help, I am going
crazy here :)!

Private Sub cmdNewOnlineMbr _Click()
On Error GoTo Err_cmdNewOnlin eMbr_Click

Dim db As Database ' Current database
Dim rsOnlineDb As Recordset ' Source table
Dim rsInhouseDb As Recordset ' Target table
Dim i As Integer ' Loop counter

DoCmd.OpenQuery "qryAddNewMembe rs"
Set db = CurrentDb()
Set rsOnlineDb = db.OpenRecordse t("Member Updates")
Set rsInhouseDb = db.OpenRecordse t("New Members")
With rsInhouseDb
' Loop through all records in source table.
Do While Not rsOnlineDb.EOF
' Add all new records to target table.
.AddNew
!MEMBERNUMBER = DMax([MEMBER NUMBER], Members) + 1
!FIRST = rsOnlineDb!Firs tName
!MI = rsOnlineDb!MI
!LAST = rsOnlineDb!Last Name
!MBRSHPEXP = rsOnlineDb!MBRS HPEXP
!NOTES = rsOnlineDb!NOTE S
!EMPLOYER = rsOnlineDb!EMPL OYER
!POSITION = rsOnlineDb!Posi tionTitle
!ADDRESS1 = rsOnlineDb!ADDR ESS1
!ADDRESS2 = rsOnlineDb!ADDR ESS2
!ADDRESS3 = rsOnlineDb!ADDR ESS3
.Update
rsOnlineDb.Move Next
Loop
End With
rsInhouseDb.Clo se
rsOnlineDb.Clos e
Exit_cmdNewOnli neMbr_Click:
Exit Sub

Err_cmdNewOnlin eMbr_Click:
MsgBox Err.Description
Resume Exit_cmdNewOnli neMbr_Click

End Sub

I'll assume the line
!MEMBERNUMBER = DMax([MEMBER NUMBER], Members) + 1
is the culprit/problem from what I gleaned in your post.

Typically I use " around each item; field name, table name, and criteria
if that is included.

For example, in the code line above, you have no reference to Members as
a variable. I might use the syntax oif
!MEMBERNUMBER = DMax("MEMBER NUMBER", "Members") + 1

Another thing I noticed...you don't update the Members table in your
code. I would think that as you loop thru the records the new records
would contain the same MemberNumber + 1 which I figure is not what you
want. Perhaps after updating the Members table you want to update the
members table as well so you stay in synch with the Max number.
Sep 11 '08 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
3519
by: Scott | last post by:
I have a database with an input form. The field "DailyID" on the form is to increment automatically with each new entry, then reset itself back to "1" at midnight and/or the change of date. However, the DAILYID increments automatically to "10" just fine, but does not go beyond "10" until the date changes. I have the following code in my form's CURRENT event: Private Sub Form_Current()
4
2266
by: lukeargent | last post by:
Hi All, I have come across some rather weird error that I can only assume is something to do with my ADP file connecting to SQL Server 2000. I'm using Access XP as my front end. In simple terms: I have a database which is in design for a new Development Request system. The main 2 tables are linked one to many, by in this instance say DWR_ID.
4
4049
by: gps | last post by:
I'm trying to use Dmax to dip into a my invoice header table and pull the maxium invoice number out of it. I'm running Access 2007 on Vista Business, but had the same prob with Access 2003 on XPP. Here's a snapshot of the table data: InvoiceID 79571 79572 ACCT ACCT
3
5819
by: Ron | last post by:
Hi All, Okay, here's the deal: Access2000/WinXP. Have a database that's split, FE/BE with multiple users having FE and one of those users also has BE (still split though...). Have a form on FE for adding/editing transactions. Using TransactionID control as autonumber/primary key for tblTransactions. A while back, when I mentioned here that I was showing that control to my users as the transaction number, someone (can't remember who...
4
2510
by: Ed Marzan | last post by:
Greetings, I have a query that returns varying prices for the same item in the following manner. Item1 Price1 Item1 Price2 Item1 Price3 Item1 Price4
4
4591
by: jacc14 | last post by:
Hi This is the second query I have had with Dmax. The first one I resolved as it was in a form and by using DMAX everytime I click for new record it gave a new order number ie dmax("ordernumber", "tbl_orders")+1. This problem is quite different and I am hoping someone out there can advice. I have a group of orders in a table. I tick a box to select which records I want to batch for that particular month. An update query then copies...
2
3423
by: ontherun | last post by:
Hi, I have a form called Customer based on the table tblCustomer and another form called Job based on the table Job when the user enter the details for the Customer i have a button at the bottm of the form called EnterJob where it directs to the Job Form I have included some code in EnterJob button so when the user clicks, it gets the value for Customer Name and Max value of the Job number and enter into the appropriate field in the...
2
5650
by: joeyrhyulz | last post by:
Hi, I'm trying to make a very simple update statement (in Oracle) in jet sql that seems much more difficult than it should be. The root of my problem is that I'm trying to update a field on a table using dmax, which references another query to update the table. Although I have all of the correct keys from the physical table joined to the query in the dmax function, the code/ms access seems to ignore the joins. As a result, all payees...
21
4625
by: DanicaDear | last post by:
I have a report named "rptHOTSTICKS_EXPIRING" based on a query named "HOSTICKS_SHIPPING_REPORT Query". The query contains these fields: ORDER_NUM (text) CUST_NUM (text) Name, address, contact info, I think not important to this thread DATE_SHIP (date) Then I have a field STICKS_EXPIRE: DateAdd("yyyy",2,) with criteria Between And where and are parameters.
0
8421
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8325
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8742
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8518
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8621
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6177
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
1
2743
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1971
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1734
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.