By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,660 Members | 1,071 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,660 IT Pros & Developers. It's quick & easy.

Unique, one-time data, programflow in Acces

P: 30
Hi,

This my problem.
After distribution of my acces-application I want the new user to be able to enter his Name-adress-etc values, in a one-row table called program-variables. These will be used tot print on reports etc.
I want this to be a one-time event. This will help to avoid illegal re-distibution.
My idea is that before updating the values ther is a check: are the fields null or not?
If not the action should be canceled.
In more general terms the question is: how can I make the programflow in acces condional to the contents of a field in a table?

I'm what you would call an advanced user of Acces, but have little knowledge of VB.
Can anyone give me directions?
Mar 1 '08 #1
Share this Question
Share on Google+
6 Replies


ADezii
Expert 5K+
P: 8,607
Hi,

This my problem.
After distribution of my acces-application I want the new user to be able to enter his Name-adress-etc values, in a one-row table called program-variables. These will be used tot print on reports etc.
I want this to be a one-time event. This will help to avoid illegal re-distibution.
My idea is that before updating the values ther is a check: are the fields null or not?
If not the action should be canceled.
In more general terms the question is: how can I make the programflow in acces condional to the contents of a field in a table?

I'm what you would call an advanced user of Access, but have little knowledge of VB.
Can anyone give me directions?
Assuming you have a Form Interface for entering this information, then in the BeforeUpdate() Event of the Form, enter code similar to the following:
Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_BeforeUpdate(Cancel As Integer)
  2. If IsNull(Me![txtFirstName]) Then
  3.   MsgBox "You must enter your First Name"
  4.     Cancel = True
  5. ElseIf IsNull(Me![txtLastName]) Then
  6.   MsgBox "You must enter your Last Name"
  7.     Cancel = True
  8. ElseIf IsNull(Me![txtAddress]) Then
  9.   MsgBox "Forgot our Address, did we?"
  10.     Cancel = True
  11. Else
  12.   'Assuming your Form is not Bound to program-variables
  13.   Dim MyDB As DAO.Database, MyRS As DAO.Recordset
  14.   Set MyDB = CurrentDb
  15.   Set MyRS = MyDB.OpenRecordset("program-variables", dbOpenTable)
  16.     With MyRS
  17.       .AddNew
  18.         MyRS![First Name] = Me![txtFirstName]
  19.         MyRS![Last Name] = Me![txtLastName]
  20.         MyRS![Address] = Me![txtAddress]
  21.       .Update
  22.     End With
  23.   MyRS.Close: Set MyRS = Nothing
  24.  
  25.   MsgBox "Record saved for " & Me![txtFirstName] & " " & Me![txtLastName]
  26. End If
  27. End Sub
NOTE: Don't forget that you must make provisions to see if the individual has already been added to program-variables before you ever Open this User Info Form. Please be advised that if you have any further questions, I'll be on vacation and will not be able to reply, but I'm sure that we will have many others willing to assist you.
Mar 2 '08 #2

P: 30
Sorry to answer so late, I was incorrectly under the impression that any answer to my post would by announced by an email.
I'm very glad to recieve such an elaborate answer.
Will look at it first thing tomorrow (its past 00.00 local time now).
Wil let you know what my findings are.
Mar 4 '08 #3

P: 30
This is not what I was looking for. Probably didn't formulate my question right. I'll try again.
On opening my acces-application, an opening-form is shown with a "start"-button, wich leads to te rest of the application.
However, when the application is not yet been used for the first time, I want the "start"-button to lead to a form where Name-adres-etc values are to be given.
The next time the application is used I do not want this to happen, but I want the "start"-button to lead directly tot the rest of the program. In this way there is only a one-time event in wich the user identify's himself to the program. It is now dedicated to him and is useless to other would-be users.

So, I want the routine in/under the "start"-button to check: Have the fields for name-adres-etc already been filled? Yes: go on to the main program. No: open the name-adres form.
Or, in other words: How do I make the response of button (or another user-driven event) conditional to the contents of a specific field in a table?
Hope I'm more intelligable now?
Mar 5 '08 #4

ADezii
Expert 5K+
P: 8,607
This is not what I was looking for. Probably didn't formulate my question right. I'll try again.
On opening my acces-application, an opening-form is shown with a "start"-button, wich leads to te rest of the application.
However, when the application is not yet been used for the first time, I want the "start"-button to lead to a form where Name-adres-etc values are to be given.
The next time the application is used I do not want this to happen, but I want the "start"-button to lead directly tot the rest of the program. In this way there is only a one-time event in wich the user identify's himself to the program. It is now dedicated to him and is useless to other would-be users.

So, I want the routine in/under the "start"-button to check: Have the fields for name-adres-etc already been filled? Yes: go on to the main program. No: open the name-adres form.
Or, in other words: How do I make the response of button (or another user-driven event) conditional to the contents of a specific field in a table?
Hope I'm more intelligable now?
The following code, placed in the Click() Event of a Command Button, will check and see if a First Name exists in tblUserInfo. tblUserInfo will consist of a [First], [Last], and [Address] Field all of which are Required, so either it contains a Record or it doesn't. No need to check the existence of all three Fields. If a value exists, open a fictitious Main Form, if it doesn't open a fictitious Name/Address Form. When I have shown you is just simply a broad guideline, more like pseudo code:
Expand|Select|Wrap|Line Numbers
  1. Private Sub cmdStart_Click()
  2. On Error GoTo Err_cmdStart_Click
  3.  
  4. If IsNull(DLookup("[First]", "tblUserInfo")) Then
  5.   DoCmd.OpenForm "frmNameAddress", acNormal, , , acFormAdd, acWindowNormal
  6. Else
  7.   DoCmd.OpenForm "frmMainProgram", acNormal, , , acFormEdit, acWindowNormal
  8. End If
  9.  
  10. Exit_cmdStart_Click:
  11.   Exit Sub
  12.  
  13. Err_cmdStart_Click:
  14.   MsgBox Err.Description, vbExclamation, "Error in cmdStart_Click()"
  15.   Resume Exit_cmdStart_Click
  16. End Sub
Is this the correct interpretation?
Mar 6 '08 #5

P: 30
You are the greatest !
May be it's simple to you, but for me its magic.
After changíng the names of the tables etc its works like a swiss clock !
Just proves to me that I should do some serious study of VB...

Thanks.
Mar 6 '08 #6

ADezii
Expert 5K+
P: 8,607
You are the greatest !
May be it's simple to you, but for me its magic.
After changíng the names of the tables etc its works like a swiss clock !
Just proves to me that I should do some serious study of VB...

Thanks.
Glad it worked out for you.
Mar 6 '08 #7

Post your reply

Sign in to post your reply or Sign up for a free account.