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 said:
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>