PC Review


Reply
Thread Tools Rate Thread

Combined ID problem - probably involving DMAX

 
 
=?Utf-8?B?U0pD?=
Guest
Posts: n/a
 
      23rd Jun 2006
I have a form which creates a project ID (can be any user specified string)
and then opens a subform to add sub-projects, which are strictly contiguous
within each project. How can I pre-populate the sub project field in the sub
form with the next sequential number for that Project based on the Project ID
of the currently open form? (All projects can have a sub project 1, the
uniqueness is enforced by combining Sub Project ID with Project ID). I'm
guessing it involves using DMAX but I can't figure out how to apply the
current Project ID as a criteria.
Hope my garbled explanation makes sense, any help gratefully received
 
Reply With Quote
 
 
 
 
Allen Browne
Guest
Posts: n/a
 
      23rd Jun 2006
If you have only one user adding records, you could use the BeforeInsert
event of the form to look up the highest number so far for that project, and
add 1.

Something like this:

Private Sub Form_BeforeInsert(Cancel As Integer)
Dim strWhere As String
If IsNull(Me.Parent![ProjectID]) Then
Cancel = True
MsgBox "Enter the project in the main form first."
ElseIf IsNull(Me.[SubProjectID])
strWhere = "[ProjectID] = """ & Me.Parent![ProjectID] & """"
Me.[SubProjectID] = Nz(DMax("[SubProjectID]", "[SubTable]",
strWhere),0) + 1
End If
End Sub

Adjust the names to suit your actual field names.

If the ProjectID in the main form is a Number field (not a Text field), drop
the extra quotes, i.e.:
strWhere = "[ProjectID] = " & Me.Parent![ProjectID]

If you have multiple users, you might prefer to use the BeforeUpdate event
of the form, since that fires at the last possible moment.

--
Allen Browne - Microsoft MVP. Perth, Western Australia.
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

"SJC" <(E-Mail Removed)> wrote in message
news:555CC139-1348-44EA-9251-(E-Mail Removed)...
>I have a form which creates a project ID (can be any user specified string)
> and then opens a subform to add sub-projects, which are strictly
> contiguous
> within each project. How can I pre-populate the sub project field in the
> sub
> form with the next sequential number for that Project based on the Project
> ID
> of the currently open form? (All projects can have a sub project 1, the
> uniqueness is enforced by combining Sub Project ID with Project ID). I'm
> guessing it involves using DMAX but I can't figure out how to apply the
> current Project ID as a criteria.
> Hope my garbled explanation makes sense, any help gratefully received



 
Reply With Quote
 
Graham R Seach
Guest
Posts: n/a
 
      23rd Jun 2006
This sort of thing should do.

SubProjectID = Nz(DMax("SubProjectID","tblSubProject","ProjectID = " &
Me.Parent.Form!txtProjectID), 0) + 1

Regards,
Graham R Seach
Microsoft Access MVP
Canberra, Australia
---------------------------

"SJC" <(E-Mail Removed)> wrote in message
news:555CC139-1348-44EA-9251-(E-Mail Removed)...
>I have a form which creates a project ID (can be any user specified string)
> and then opens a subform to add sub-projects, which are strictly
> contiguous
> within each project. How can I pre-populate the sub project field in the
> sub
> form with the next sequential number for that Project based on the Project
> ID
> of the currently open form? (All projects can have a sub project 1, the
> uniqueness is enforced by combining Sub Project ID with Project ID). I'm
> guessing it involves using DMAX but I can't figure out how to apply the
> current Project ID as a criteria.
> Hope my garbled explanation makes sense, any help gratefully received



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
AD Problem involving FRS =?Utf-8?B?VGhlTWFtbW90aE1hbg==?= Microsoft Windows 2000 Active Directory 5 18th Jul 2007 07:54 AM
Security problem involving WGA Bert Windows XP Security 1 17th Aug 2006 01:55 PM
DMax for dates in rpt group header returns DMax for entire records =?Utf-8?B?aGVsaW9z?= Microsoft Access Getting Started 1 19th Jul 2005 09:32 PM
Registry problem involving DatNetInstaller.exe =?Utf-8?B?TWFydGluIFNhY2hz?= Windows XP General 2 28th Nov 2004 12:55 PM
Has anyone ever had a problem involving the shift key?? =?Utf-8?B?ZWRq?= Windows XP General 7 5th Aug 2004 08:30 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 09:31 PM.