473,372 Members | 1,036 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,372 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 6685
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...
1
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: 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...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.