A Microsoft Office (Excel, Word) forum. OfficeFrustration

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » OfficeFrustration forum » Microsoft Access » Using Forms
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

Form used for ADD and CHANGE?



 
 
Thread Tools Display Modes
  #1  
Old March 22nd, 2007, 03:18 PM posted to microsoft.public.access.forms
meg
external usenet poster
 
Posts: 105
Default Form used for ADD and CHANGE?

My question relates to best methods.

The application has a "swithboard" type form that allows the user to:

1) ADD a test
2) REVIEW a test (allows for changing the data)

Is it best (or is there a great technique or tip) to use one FORM for this
and set it to either do an ADD or REVIEW based on the call from the
"switchboard" form.

THANKS,

MEG


  #2  
Old March 22nd, 2007, 03:47 PM posted to microsoft.public.access.forms
Carl Rapson
external usenet poster
 
Posts: 517
Default Form used for ADD and CHANGE?

That would be my recommendation, as it gives you only one form to maintain.
You can pass a string such as "ADD" or "REVIEW" to the form when it opens
(in the DoCmd.OpenForm call), and in the Form_Open or Form_Load event take
appropriate steps depending on which string was passed.

Carl Rapson

"MEG" wrote in message
...
My question relates to best methods.

The application has a "swithboard" type form that allows the user to:

1) ADD a test
2) REVIEW a test (allows for changing the data)

Is it best (or is there a great technique or tip) to use one FORM for this
and set it to either do an ADD or REVIEW based on the call from the
"switchboard" form.

THANKS,

MEG




  #3  
Old March 23rd, 2007, 04:27 AM posted to microsoft.public.access.forms
meg
external usenet poster
 
Posts: 105
Default Form used for ADD and CHANGE?

Thank you for the response.

Since I sent this post, I met with the user. The access database is used
after doing some functions in another application. This application has
functionality to call the access database with a command line. Therefore, to
make it easier for the user, I'm looking to incorporate the command line into
the access database.

I have started this process and I'm passing the following:

FORM ACCOUNT ACTION

FORM can be one of three (FORM1, FORM2, FORM3)
ACCOUNT is the ACCOUNT number they want to add or display a record
ACTION is the whether to ADD a record for the ACCOUNT or DISPLAY a record
for the ACCOUNT

I've successfully broken the command line into the 3 above parts.

What I could use help with is the code to open the form and do the two
actions.

THANKS,

MEG

"Carl Rapson" wrote:

That would be my recommendation, as it gives you only one form to maintain.
You can pass a string such as "ADD" or "REVIEW" to the form when it opens
(in the DoCmd.OpenForm call), and in the Form_Open or Form_Load event take
appropriate steps depending on which string was passed.

Carl Rapson

"MEG" wrote in message
...
My question relates to best methods.

The application has a "swithboard" type form that allows the user to:

1) ADD a test
2) REVIEW a test (allows for changing the data)

Is it best (or is there a great technique or tip) to use one FORM for this
and set it to either do an ADD or REVIEW based on the call from the
"switchboard" form.

THANKS,

MEG





  #4  
Old March 23rd, 2007, 02:32 PM posted to microsoft.public.access.forms
Carl Rapson
external usenet poster
 
Posts: 517
Default Form used for ADD and CHANGE?

After you've parsed the command line (I assume that's what you meant by
'broken'), open the form as follows:

DoCmd.OpenForm strForm,,,,,,strAccount & "+" & strAction

This assumes:

1. strForm contains the name of the form to open
2. strAccount contains the Account number. The syntax above assumes the
account number is a string; if it's numeric, remove the single quotes:

DoCmd.OpenForm strForm,,,,,,strAccount & "+" & strAction

3. strAction contains the action to be performed

Note that I'm concatenating the Account and Action strings together,
separating them by a "+" just so we have something to parse them by. If
there is a chance that the Account string will contain a plus sign, you can
use any other character you wish to separate the two strings.

In the form's Open event, parse the Account and Action strings into
module-level variables (declared at the top of the module, before the first
procedure):

Dim strAccount As String
' if Account is numeric, declare as follows
' Dim lngAccount As Long
Dim strAction As String
...
Private Sub Form_Open()
strAccount = Left(Me.OpenArgs, InStr(Me.OpenArgs, "+") - 1)
strAction = Right(Me.OpenArgs, Len(Me.OpenArgs)-InStr(Me.OpenArgs,
"+"))
End Sub

In the form's Load event, check the action as follows:

If Me.OpenArgs = "ADD" Then
' Add a new record for the Account
DoCmd.GotoRecord , , acNewRec
Me![Account] = strAccount
ElseIf Me.OpenArgs = "DISPLAY" Then
' Locate the record for this Account
Dim rs as Recordset
set rs = Me.RecordsetClone
rs.FindFirst "[Account] = '" & strAccount & "'"
' if Account is numeric, use the following line instead:
' rs.FindFirst "[Account]=" & lngAccount
If Not rs.NoMatch Then
Me.Bookmark = rs.Bookmark
Else
' Account not found!
End If
rs.Close
Set rs = Nothing
Else
' In case there is another possibility for the Action
End If

Understand, these are just some ideas. Be sure you use your own field names
in place of the ones I've made up. If you're using ADO instead of DAO,
you'll need to change the code for the DISPLAY action accordingly; use VBA's
Help for more information. You can also search these newsgroups for more
information; all of these topics are discussed frequently.

Hopefully this will get you started.

Carl Rapson

"MEG" wrote in message
...
Thank you for the response.

Since I sent this post, I met with the user. The access database is used
after doing some functions in another application. This application has
functionality to call the access database with a command line. Therefore,
to
make it easier for the user, I'm looking to incorporate the command line
into
the access database.

I have started this process and I'm passing the following:

FORM ACCOUNT ACTION

FORM can be one of three (FORM1, FORM2, FORM3)
ACCOUNT is the ACCOUNT number they want to add or display a record
ACTION is the whether to ADD a record for the ACCOUNT or DISPLAY a record
for the ACCOUNT

I've successfully broken the command line into the 3 above parts.

What I could use help with is the code to open the form and do the two
actions.

THANKS,

MEG

"Carl Rapson" wrote:

That would be my recommendation, as it gives you only one form to
maintain.
You can pass a string such as "ADD" or "REVIEW" to the form when it opens
(in the DoCmd.OpenForm call), and in the Form_Open or Form_Load event
take
appropriate steps depending on which string was passed.

Carl Rapson

"MEG" wrote in message
...
My question relates to best methods.

The application has a "swithboard" type form that allows the user to:

1) ADD a test
2) REVIEW a test (allows for changing the data)

Is it best (or is there a great technique or tip) to use one FORM for
this
and set it to either do an ADD or REVIEW based on the call from the
"switchboard" form.

THANKS,

MEG







  #5  
Old March 23rd, 2007, 02:35 PM posted to microsoft.public.access.forms
Carl Rapson
external usenet poster
 
Posts: 517
Default Form used for ADD and CHANGE?

After you've parsed the command line (I assume that's what you meant by
'broken'), open the form as follows:

DoCmd.OpenForm strForm,,,,,,strAccount & "+" & strAction

This assumes:

1. strForm contains the name of the form to open
2. strAccount contains the Account number. The syntax above assumes the
account number is a string; if it's numeric, remove the single quotes:

DoCmd.OpenForm strForm,,,,,,strAccount & "+" & strAction

3. strAction contains the action to be performed

Note that I'm concatenating the Account and Action strings together,
separating them by a "+" just so we have something to parse them by. If
there is a chance that the Account string will contain a plus sign, you can
use any other character you wish to separate the two strings.

In the form's Open event, parse the Account and Action strings into
module-level variables (declared at the top of the module, before the first
procedure):

Dim strAccount As String
' if Account is numeric, declare as follows
' Dim lngAccount As Long
Dim strAction As String
...
Private Sub Form_Open()
strAccount = Left(Me.OpenArgs, InStr(Me.OpenArgs, "+") - 1)
strAction = Right(Me.OpenArgs, Len(Me.OpenArgs)-InStr(Me.OpenArgs,
"+"))
End Sub

In the form's Load event, check the action as follows:

If Me.OpenArgs = "ADD" Then
' Add a new record for the Account
DoCmd.GotoRecord , , acNewRec
Me![Account] = strAccount
ElseIf Me.OpenArgs = "DISPLAY" Then
' Locate the record for this Account
Dim rs as Recordset
set rs = Me.RecordsetClone
rs.FindFirst "[Account] = '" & strAccount & "'"
' if Account is numeric, use the following line instead:
' rs.FindFirst "[Account]=" & lngAccount
If Not rs.NoMatch Then
Me.Bookmark = rs.Bookmark
Else
' Account not found!
End If
rs.Close
Set rs = Nothing
Else
' In case there is another possibility for the Action
End If

Understand, these are just some ideas and I haven't actually tested the code
above. Be sure you use your own field names in place of the ones I've made
up. If you're using ADO instead of DAO, you'll need to change the code for
the DISPLAY action accordingly; use VBA's Help for more information. You can
also search these newsgroups for more information; all of these topics are
discussed frequently.

Hopefully this will get you started.

Carl Rapson

"MEG" wrote in message
...
Thank you for the response.

Since I sent this post, I met with the user. The access database is used
after doing some functions in another application. This application has
functionality to call the access database with a command line. Therefore,
to
make it easier for the user, I'm looking to incorporate the command line
into
the access database.

I have started this process and I'm passing the following:

FORM ACCOUNT ACTION

FORM can be one of three (FORM1, FORM2, FORM3)
ACCOUNT is the ACCOUNT number they want to add or display a record
ACTION is the whether to ADD a record for the ACCOUNT or DISPLAY a record
for the ACCOUNT

I've successfully broken the command line into the 3 above parts.

What I could use help with is the code to open the form and do the two
actions.

THANKS,

MEG


snipped


 




Thread Tools
Display Modes

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 Off
HTML code is Off
Forum Jump


All times are GMT +1. The time now is 12:31 AM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 OfficeFrustration.
The comments are property of their posters.