Connecting Tech Pros Worldwide Help | Site Map

Using a VB function to update records

 
LinkBack Thread Tools Search this Thread
  #1  
Old November 12th, 2005, 09:22 PM
Sid
Guest
 
Posts: n/a
Default Using a VB function to update records

Hi,
I have a VB function that calculates a spatial point from a bearing
and distance. I need to be able to update point co-ordinates (Lat and
Longs) in the Db with the function. I can call the function to do an
insert but not an update. I coded the sql as follows.

UPDATE x_CoordFix SET x_CoordFix.oldlat = (Select
X_From_BrgDist([clnBearing],[clnDistance],[clnViewPointLongitude],[clnViewPointLatitude)
FROM tblSurvey1MinedArea INNER JOIN tblSurvey1 ON
[tblSurvey1MinedArea].[clnSurveyGUID]=[tblSurvey1].[clnGUID]);

X_From_BrgDist() is the function that returns a Latitude point.

I receive an error "Operation must be an updatable query"

Has anyone any ideas what I've done wrong.

Regs
Sid

  #2  
Old November 12th, 2005, 09:23 PM
Noam Nelke
Guest
 
Posts: n/a
Default Re: Using a VB function to update records

Hi Sid,

You may be able to use an update query to do what you try to do, but I
don't know that much about those. What I would do is work with a
recordset, from code.

In order to open a recordset you must first include a reference to
Microsoft DAO Object Library (in the VB editor click Tools, then
References, browse down to Microsoft DAO 3.6 Object Library, and check
it). Then you declare the Recordset by writing the following line of
code:

Dim rs As DAO.Recordset

"rs" is the name of the recordset, you may, and should, change it.
Next you build the rs by writing the following:

Set rs = CurrentDB.OpenRecordset("<Your Select Query goes here>")

Then you have several commands you can use on the recordset:

rs.MoveFirst - Moves to the first record in the recordset.
rs.MoveNext - Obviously, moves to the next...
rs.MoveLast - too obvious...
rs.Edit - Opens the current record for editing.
rs.Update - Saves changes you made to the table. You must use this
method
before moving to the next record or changes are lost.

to access fields in your table just use:

rs!<name_of_your_field>

They'll behave almost like a variable, which is most conveniant.

Hope this helps...

Noam Nelke, Israel.
 

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Popular Articles

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over 220,662 network members.