473,320 Members | 1,969 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Help for write VBA code using "Command" function and "GoToRecord" action

I working on a GIS project, with Access link which just need a little
routine in VBA, but I haven't knowledges in VBA language.

It's very simple, and it looks like that in a TPascal way :

....
Var
RecordNb : integer ;
....
{Command : function of Access}
....
{GoToRecord : method of Acces}

Begin
If Command=Null then
RecordNb:=1
Else
RecordNb:=Command;
GoToRecord(RecordNb);
End.

Could someone write me how it looks like in VBA ?
Nov 12 '05 #1
6 6678
I don't understand what it is you are trying to do. Move to a record on a
form? In a Recordset? Automate Access from another application? What version
of Access? ADO or DAO?

Mike Storr
www.veraccess.com
"Clément Collin" <cl************@club-internet.fr> wrote in message
news:40**********************@news.club-internet.fr...
I working on a GIS project, with Access link which just need a little
routine in VBA, but I haven't knowledges in VBA language.

It's very simple, and it looks like that in a TPascal way :

...
Var
RecordNb : integer ;
...
{Command : function of Access}
...
{GoToRecord : method of Acces}

Begin
If Command=Null then
RecordNb:=1
Else
RecordNb:=Command;
GoToRecord(RecordNb);
End.

Could someone write me how it looks like in VBA ?

Nov 12 '05 #2
Thanks for your interest.

First, I am not a a professionnal computerist, furthermore I am french, what
can explain the unprecise way the issue is explained.

I try to clarify.

I work on the construction of an archaeological GIS. The softwares used are
ESRI Arcview 3.2 and MS Access 2003, and I don't know if it is ADO or DAO.
Arcview use a language called "Avenue" derived from "SmallTalk".

I want like you said to "Automate Access from other application" (from
Arcview). Precisely, I want to go to a specific record in a form when I
click on an object displaied in Arcview. For example : if I click on the
object which ID attribute is 10, it opens Access, and directly display the
form of the record which ID is 10.

To do that, I can make Arcview execute a shell command and send a parameter
: ID of the object (here C:\...\MSAccess.exe <DatabaseName> /cmd <ID of the
object>).

I've configure my database to open the wanted Form automatically. And I just
want to program a little Visual Basic macro to receive the parameter, and
use it to go automatically to the specified record, corresponding with the
ID of the object.

That's it. And I think if I could write in VB the program I've written in
Tpascal, I could work.

What do you think ? Have I to contract computerists ?

"Mike Storr" <no****@somewhere.con> escribió en el mensaje
news:mZ********************@news20.bellglobal.com. ..
I don't understand what it is you are trying to do. Move to a record on a
form? In a Recordset? Automate Access from another application? What version of Access? ADO or DAO?

Mike Storr
www.veraccess.com
"Clément Collin" <cl************@club-internet.fr> wrote in message
news:40**********************@news.club-internet.fr...
I working on a GIS project, with Access link which just need a little
routine in VBA, but I haven't knowledges in VBA language.

It's very simple, and it looks like that in a TPascal way :

...
Var
RecordNb : integer ;
...
{Command : function of Access}
...
{GoToRecord : method of Acces}

Begin
If Command=Null then
RecordNb:=1
Else
RecordNb:=Command;
GoToRecord(RecordNb);
End.

Could someone write me how it looks like in VBA ?


Nov 12 '05 #3
I'm not really familiar with the languages you are using, but perhaps using
the /cmd switch for the database you are working with would work. You could
pass a command line setting, ie. the record number as a string. Then when
the form opens, use the Command function to get that record number. Convert
the result to a number, then move to the desired record. Try placing this in
the OnOpen event of the form...

Dim recNum As Long
recNum = CLng(Command())
DoCmd.GoToRecord acActiveDataObject, "formName", acGoTo, recnum
"Clément Collin" <cl************@club-internet.fr> wrote in message
news:40**********************@news.club-internet.fr...
Thanks for your interest.


Nov 12 '05 #4
"Clément Collin" <cl************@club-internet.fr> wrote in message
news:40**********************@news.club-internet.fr...
Thanks for your interest.

First, I am not a a professionnal computerist, furthermore I am french, what can explain the unprecise way the issue is explained.

I try to clarify.

I work on the construction of an archaeological GIS. The softwares used are ESRI Arcview 3.2 and MS Access 2003, and I don't know if it is ADO or DAO.
Arcview use a language called "Avenue" derived from "SmallTalk".

I want like you said to "Automate Access from other application" (from
Arcview). Precisely, I want to go to a specific record in a form when I
click on an object displaied in Arcview. For example : if I click on the
object which ID attribute is 10, it opens Access, and directly display the
form of the record which ID is 10.

To do that, I can make Arcview execute a shell command and send a parameter : ID of the object (here C:\...\MSAccess.exe <DatabaseName> /cmd <ID of the object>).

I've configure my database to open the wanted Form automatically. And I just want to program a little Visual Basic macro to receive the parameter, and
use it to go automatically to the specified record, corresponding with the
ID of the object.

That's it. And I think if I could write in VB the program I've written in
Tpascal, I could work.

What do you think ? Have I to contract computerists ?



You can extract information from the database without opening it using
Access, but if you really do need Access to open and show a form, then you
could do this:

Assuming the name of the form is "frmMyForm" and the primary key is called
"ID" and is a long integer.

You need 3 steps:

1. Create and name it "AutoExec" In the design of the macro give it one
step which is to RunCode. In the function box at the bottom, write
=Startup()

2. Create a new module and name it "modStartup".
' ************************************************
Option Compare Database
Option Explicit

Public Function Startup()

On Error GoTo Err_Handler

Dim strCommand As String
Dim lngID As Long

strCommand = Nz(Command(), "")

If Len(strCommand) = 0 Then Exit Function

lngID = CLng(strCommand)

DoCmd.RunCommand acCmdAppMaximize

DoCmd.OpenForm "frmMyForm", , , , , , lngID

Exit_Handler:
Exit Function

Err_Handler:
MsgBox Err.Description, vbExclamation, "Error No: " & Err.Number
Resume Exit_Handler

End Function

' ************************************************

3. In the form's code module, paste the following
' ************************************************
Option Compare Database
Option Explicit

Private Sub Form_Open(Cancel As Integer)

On Error GoTo Err_Handler

If IsNull(Me.OpenArgs) Then Exit Sub

With Me.RecordsetClone
.FindFirst "[ID]=" & Me.OpenArgs
If Not .NoMatch Then
Me.Bookmark = .Bookmark
Else
MsgBox "Record Not Found", vbCritical
Cancel = True
End If
End With

Exit_Handler:
Exit Sub

Err_Handler:
MsgBox Err.Description, vbExclamation, "Error No: " & Err.Number
Resume Exit_Handler

End Sub

' ************************************************
HTH

Fletcher
Nov 12 '05 #5
Works perfectly. Very thanks to you. I'm saved.
(the only matter is that each time the shell executes, if Access is opened,
it opens a new Access Windows with a new copy of the same database)
Nov 12 '05 #6
Works perfectly. Very thanks to you. I'm saved.
(the only matter is that each time the shell executes, if Access is opened,
it opens a new Access Windows with a new copy of the same database)

Nov 12 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

15
by: sara | last post by:
Hi I'm pretty new to Access here (using Access 2000), and appreciate the help and instruction. I gave myself 2.5 hours to research online and help and try to get this one, and I am not getting...
7
by: Mathew Butler | last post by:
I'm investigating an issue I have when pulling data back from MS access I'm retrieving all rows from a column in a table of 5000 rows - accessing a column of type "memo" ( can be 65353 character...
1
by: AA Arens | last post by:
I my form I have put record navigation buttons. When I choose just before the last record, the "Go to next record" button, access automatically start with a new record instead of a message that...
5
by: djsdaddy | last post by:
Good Day All, I have some EEO data in an old dBase4 database that I have converted to an Access table. Since dBase was not a relational database, I didn't create any key fields. I linked all of the...
2
by: teric2 | last post by:
Hello again. I have the following code attached to the onclick event of a command button: Dim strQry As String strQry = "INSERT INTO () VALUES ('" & Me!Text80 & "')" DoCmd.RunSQL...
7
by: JKoyis | last post by:
I'm having some trouble with the code on this form - it's intended to increment the grades of all the students in the database. If I open the form in design view and then switch to normal view it...
3
rsmccli
by: rsmccli | last post by:
Using AC2002 Hello. I am working with an existing DB that has "Add New" command buttons on two forms. When I, an Admin, click the buttons, they work properly, and a new, blank form is created,...
7
by: MLH | last post by:
If I'm using the following in a procedure... DoCmd.GoToRecord acDataForm, "FormName", acNext, 4 .... how can I recognize the EOF condition? Using GoToRecord, I find myself lost when trying to...
3
by: MyWaterloo | last post by:
I am trying to open my purchase orders form and go to the last record. In the on open command I do: DoCmd.GoToRecord , , acLast Seems straight forward enough...but I keep getting this message...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.