Visual Basic Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming Languages - MoreVisual Basic Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
Anyone looking for a way to modernize legacy data or easily migrate to a more cost-effective database without sacrificing functionality will benefit from this seminar. View the Intro to Advantage Database Server now!
  #1  
Old February 5th, 2003, 12:08 PM
bogglebeats bogglebeats is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2003
Posts: 21 bogglebeats User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 6 m 47 sec
Reputation Power: 0
Generating Field Value

Hello. I am trying to display the values of fields called 'session number' and 'session date' by clicking on a command button in Access. I would like to incorporate VB code in the click action of the button. The button is called 'New Session Yes' and once this is clicked i want to start a new session with the session number and current date displayed in fields 'Session Number' and 'Session Date'. Would i do all of this coding in the onclick command property of 'New Session Yes'? The session number field corresponds to the record number, so if the new record is record #5 then, the session number should also = 5. How would i display the value in these fields. i don't know much about vb and it's syntax.

i got this code from somone else, but i don't think it is what i want it to do.

Option Compare Database
Dim iLastSession As Integer

Private Sub New_Session_Yes_Click()
On Error GoTo Err_New_Session_Yes_Click

DoCmd.GoToRecord , , acNewRec
MsgBox "Last Session: " & iLastSession
MsgBox "Selected Session: " & Session_Number.Value

If iLastSession >= Session_Number.Value Then
MsgBox "You already chose this. Select another session.", vbCritical
Else
iLastSession = Session_Number.Value
End If
Exit_New_Session_Yes_Click:
Exit Sub

Err_New_Session_Yes_Click:
MsgBox Err.Description
Resume Exit_New_Session_Yes_Click


End Sub

someone please help! thanks.

ameen

Reply With Quote
  #2  
Old February 6th, 2003, 04:59 PM
dcaillouet's Avatar
dcaillouet dcaillouet is offline
Big Endian
Dev Shed Beginner (1000 - 1499 posts)
 
Join Date: May 2001
Location: Fly-over country
Posts: 1,173 dcaillouet User rank is Sergeant (500 - 2000 Reputation Level)dcaillouet User rank is Sergeant (500 - 2000 Reputation Level)dcaillouet User rank is Sergeant (500 - 2000 Reputation Level)dcaillouet User rank is Sergeant (500 - 2000 Reputation Level)dcaillouet User rank is Sergeant (500 - 2000 Reputation Level) 
Time spent in forums: 16 h 29 m 5 sec
Reputation Power: 24
You could do it using the CurrentRecord property to get the record number of your current record and the new record. Does something like this help?

Option Compare Database

Private Sub New_Session_Yes_Click()
On Error GoTo Err_New_Session_Yes_Click

MsgBox "Last Session: " & CurrentRecord & " " & Format(Now(), "mm/dd/yyyy")
DoCmd.GoToRecord , , acNewRec
MsgBox "Selected Session: " & CurrentRecord & " " & Format(Now(), "mm/dd/yyyy")

Exit_New_Session_Yes_Click:
Exit Sub

Err_New_Session_Yes_Click:
MsgBox Err.Description
Resume Exit_New_Session_Yes_Click

End Sub

Reply With Quote
  #3  
Old February 7th, 2003, 05:23 PM
bogglebeats bogglebeats is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2003
Posts: 21 bogglebeats User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 6 m 47 sec
Reputation Power: 0
Yes this is the format i was looking for. But how do i get the proper session number to display. I got the new record to come up with the current date however the session number is giving me problems. the primary key in this is the session id. should i pass the session id value in order to display the session number? Session_Number_Textbox.Value = acLast +1 is giving me trouble. if so, how would i do this? here is the code:

Private Sub New_Session_Yes_Click()
> > On Error GoTo Err_New_Session_Yes_Click
> >
> > DoCmd.GoToRecord , , acNewRec
> > Session_Number_Textbox.Value = acLast + 1
> > Session_Date.Value = Now()
> >
> > Exit_New_Session_Yes_Click:
> > Exit Sub
> >
> > Err_New_Session_Yes_Click:
> > MsgBox Err.Description
> > Resume Exit_New_Session_Yes_Click
> >
> > End Sub

Reply With Quote
  #4  
Old February 8th, 2003, 09:12 AM
dcaillouet's Avatar
dcaillouet dcaillouet is offline
Big Endian
Dev Shed Beginner (1000 - 1499 posts)
 
Join Date: May 2001
Location: Fly-over country
Posts: 1,173 dcaillouet User rank is Sergeant (500 - 2000 Reputation Level)dcaillouet User rank is Sergeant (500 - 2000 Reputation Level)dcaillouet User rank is Sergeant (500 - 2000 Reputation Level)dcaillouet User rank is Sergeant (500 - 2000 Reputation Level)dcaillouet User rank is Sergeant (500 - 2000 Reputation Level) 
Time spent in forums: 16 h 29 m 5 sec
Reputation Power: 24
You say its giving you problems but you don't specify what kind of problem.

If you want the session id to be one greater than the last session id, is there a reason you're not making this an autonumber? Manually assigning this value can be problematic especially in a multi-user environment.

Reply With Quote
  #5  
Old February 8th, 2003, 11:54 AM
bogglebeats bogglebeats is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2003
Posts: 21 bogglebeats User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 6 m 47 sec
Reputation Power: 0
the value acLast + 1 (which i have set for the session_number_textbox.value) is not giving me the correct session number. For some reason, acLast + 1 = 4 which is the same for all clients (no matter how many sessions they have had). The value will is fixed and will not change accordingly to the number of sessions per client. session id is the unique identifier for each session where session number is the number of sessions each client has, so it is not linear like session id. many clients can have the same session number, but within each of their own attributes i need an automatic session number to be created. if the next session id in line is 55 and that particular client has already had 3 sessions, i would need 4 to come in the in the session number field. the session id is just to identify the sessions uniquely, but the session number tells me how many times each client has been counseled. is there a way to see what the last value is of the session number for each client and add 1 to that to be displayed when a new record is created? could this not be done in a simple one-line way as the date value is also determined? thanks.

ameen

Last edited by bogglebeats : February 8th, 2003 at 12:01 PM.

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - MoreVisual Basic Programming > Generating Field Value


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

 Free IT White Papers!
 
Accelerating Trading Partner Performance
One in five. That's how many partner transactions have at least one error. That is an amazing statistic, particularly given the extraordinary leaps in innovation across the global supply chain during the past two decades. Download this white paper to learn more.

 
Competing on Analytics
This Tech Analysis is designed to help identify characteristics shared by analytics competitors, and includes information about 32 organizations that have made a commitment to quantitative, fact-based analysis.

 
Cost Effective Scaling with Virtualization and Coyote Point Systems
An overview of the industry trend toward virtualization, how server consolidation has increased the importance of application uptime and the steps being taken to integrate load balancing technology with virtualized servers.

 
Five Checkpoints to Implementing IP Telephony
Implementation planning for IP PBX software and IP telephony has become vital as businesses replace discontinued legacy PBX phone systems. This informative whitepaper outlines five "checkpoints" for any implementation plan that will help make IP communications a successful proposition.

 
Hosted Email Security: Staying Ahead of New Threats
In the last two years, email has become a fierce battleground between the nefarious forces of spam and malware, and the heroes of messaging protection. The spam volumes increased alarmingly every month, bringing clever new forms of phishing and virus propagation attacks.

 

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 5 hosted by Hostway