Select database record in VBA

How do I write VBA that assigns selects my database record - like I would do
manually by right-clicking the linked shape and pick the record. I know
whick record I am looking for because it is the shape's ID - as I have
exported all my records to the database.


0
chuck4097 (19)
12/16/2003 3:20:51 PM
visio 3638 articles. 1 followers. Follow

5 Replies
776 Views

Similar Articles

[PageSpeed] 54

You would need to add a Project reference to one of the data connection
methods like ADO.
Instance a connection object to the DSN and link the shape property to the
database record.

"Chuck" <Chuck@nomail.com> wrote in message
news:npFDb.4186$QH1.3100@news.get2net.dk...
> How do I write VBA that assigns selects my database record - like I would
do
> manually by right-clicking the linked shape and pick the record. I know
> whick record I am looking for because it is the shape's ID - as I have
> exported all my records to the database.
>
>


0
asdf2235 (47)
12/16/2003 6:29:49 PM
OK - if you had some sample code - it would be very helpful.

I know how to loop through all my shapes - but I don't know the code to make
the link. I guess I woudl link to "Microsoft 3.6 DAO Object Library" and
then try to get it right... but an example would still be nice.

"RA" <asdf@microsoft.com> wrote in message
news:3fdf4f28$1@news.microsoft.com...
> You would need to add a Project reference to one of the data connection
> methods like ADO.
> Instance a connection object to the DSN and link the shape property to the
> database record.
>
> "Chuck" <Chuck@nomail.com> wrote in message
> news:npFDb.4186$QH1.3100@news.get2net.dk...
> > How do I write VBA that assigns selects my database record - like I
would
> do
> > manually by right-clicking the linked shape and pick the record. I know
> > whick record I am looking for because it is the shape's ID - as I have
> > exported all my records to the database.
> >
> >
>
>


0
chuck4097 (19)
12/16/2003 6:59:30 PM
I need an example showing what the link information looks like in the Visio
shape in VBA - like the connection I can set up manually as described in my
first post.
"RA" <asdf@microsoft.com> wrote in message
news:3fdf4f28$1@news.microsoft.com...
> You would need to add a Project reference to one of the data connection
> methods like ADO.
> Instance a connection object to the DSN and link the shape property to the
> database record.
>
> "Chuck" <Chuck@nomail.com> wrote in message
> news:npFDb.4186$QH1.3100@news.get2net.dk...
> > How do I write VBA that assigns selects my database record - like I
would
> do
> > manually by right-clicking the linked shape and pick the record. I know
> > whick record I am looking for because it is the shape's ID - as I have
> > exported all my records to the database.
> >
> >
>
>


0
chuck4097 (19)
12/16/2003 7:59:47 PM
You might try something like this ----
al


' this is used by the cell changed event to allow us to just change a
' single cell in a record, rather than full record updates. work in
' progress

Public Sub subDiscreteFieldUpdate(strTable As String, strIndex As String,
strGUID As String, strField As String, strValue As String)

Dim intResult As Integer
Dim str_db_filename As String
Dim db As Database
Dim visDocument As Visio.Document
Dim visPage As Visio.Page
Dim SaveErr As Long
Dim errDB As ADODB.Error

Dim cnn As New ADODB.Connection
Dim rst As New ADODB.Recordset

Dim strProvider As String
Dim strSource As String
Dim strConn As String
Dim strSelect As String

strProvider = "PROVIDER=Microsoft.Jet.OLEDB.4.0;"
strSource = "Data Source="
Dim strProviderED As String
strProviderED = ";"

        On Error GoTo DiscreteField_Exit

        'first we have to find out which database is associated with this
document
        Set visDocument = Visio.ActiveDocument
        Set visPage = visDocument.Pages.item("Project Definition")
        str_db_filename = visDocument.Path &
visPage.PageSheet.Cells("prop.database_file.value").ResultStr("")

        strConn = strProvider & strSource & str_db_filename & strProviderED
        cnn.Open strConn

        strSelect = "SELECT * FROM " & strTable & " Where " & strIndex & " =
" & strGUID
        rst.Open strSelect, cnn, adOpenKeyset, adLockOptimistic

        If (rst.BOF And rst.EOF) Then
            ' Debug.Print "err discrete field update " & strGUID & " record
not found"
            GoTo DiscreteField_Exit
        End If

        ' MsgBox strValue
        rst.Fields(strField).Value = strValue
        rst.Update


DiscreteField_Exit:
        rst.Close
        cnn.Close
        DoEvents

Exit Sub

DiscreteField_Err:
  SaveErr = Err.Number
    If SaveErr <> 0 Then
        Debug.Print "Err in subDiscreteFieldUpdate is " & Err & " " &
Err.Description
        Debug.Print strGUID & " " & strField & " " & strValue

        For Each errDB In cnn.Errors
            Debug.Print "DB Update " & " " & strGUID & " " & strField & " "
& strValue
            Debug.Print "DB Description: " & errDB.Description
            Debug.Print "DB Number: " & errDB.Number & " (" & _
                Hex$(errDB.Number) & ")"
            Debug.Print "JetErr: " & errDB.SQLState
        Next
        ' Resume DiscreteField_Exit:
    End If

End Sub

"Chuck" <Chuck@nomail.com> wrote in message
news:npFDb.4186$QH1.3100@news.get2net.dk...
> How do I write VBA that assigns selects my database record - like I would
do
> manually by right-clicking the linked shape and pick the record. I know
> whick record I am looking for because it is the shape's ID - as I have
> exported all my records to the database.
>
>


0
edlund1 (616)
12/16/2003 8:13:44 PM
How do I declare the ADODB?

Do I need a special reference to make it known to my module?

"Al Edlund" <edlund@ameritech.net> wrote in message
news:eAdFfEBxDHA.2116@TK2MSFTNGP11.phx.gbl...
> You might try something like this ----
> al
>
>
> ' this is used by the cell changed event to allow us to just change a
> ' single cell in a record, rather than full record updates. work in
> ' progress
>
> Public Sub subDiscreteFieldUpdate(strTable As String, strIndex As String,
> strGUID As String, strField As String, strValue As String)
>
> Dim intResult As Integer
> Dim str_db_filename As String
> Dim db As Database
> Dim visDocument As Visio.Document
> Dim visPage As Visio.Page
> Dim SaveErr As Long
> Dim errDB As ADODB.Error
>
> Dim cnn As New ADODB.Connection
> Dim rst As New ADODB.Recordset
>
> Dim strProvider As String
> Dim strSource As String
> Dim strConn As String
> Dim strSelect As String
>
> strProvider = "PROVIDER=Microsoft.Jet.OLEDB.4.0;"
> strSource = "Data Source="
> Dim strProviderED As String
> strProviderED = ";"
>
>         On Error GoTo DiscreteField_Exit
>
>         'first we have to find out which database is associated with this
> document
>         Set visDocument = Visio.ActiveDocument
>         Set visPage = visDocument.Pages.item("Project Definition")
>         str_db_filename = visDocument.Path &
> visPage.PageSheet.Cells("prop.database_file.value").ResultStr("")
>
>         strConn = strProvider & strSource & str_db_filename &
strProviderED
>         cnn.Open strConn
>
>         strSelect = "SELECT * FROM " & strTable & " Where " & strIndex & "
=
> " & strGUID
>         rst.Open strSelect, cnn, adOpenKeyset, adLockOptimistic
>
>         If (rst.BOF And rst.EOF) Then
>             ' Debug.Print "err discrete field update " & strGUID & "
record
> not found"
>             GoTo DiscreteField_Exit
>         End If
>
>         ' MsgBox strValue
>         rst.Fields(strField).Value = strValue
>         rst.Update
>
>
> DiscreteField_Exit:
>         rst.Close
>         cnn.Close
>         DoEvents
>
> Exit Sub
>
> DiscreteField_Err:
>   SaveErr = Err.Number
>     If SaveErr <> 0 Then
>         Debug.Print "Err in subDiscreteFieldUpdate is " & Err & " " &
> Err.Description
>         Debug.Print strGUID & " " & strField & " " & strValue
>
>         For Each errDB In cnn.Errors
>             Debug.Print "DB Update " & " " & strGUID & " " & strField & "
"
> & strValue
>             Debug.Print "DB Description: " & errDB.Description
>             Debug.Print "DB Number: " & errDB.Number & " (" & _
>                 Hex$(errDB.Number) & ")"
>             Debug.Print "JetErr: " & errDB.SQLState
>         Next
>         ' Resume DiscreteField_Exit:
>     End If
>
> End Sub
>
> "Chuck" <Chuck@nomail.com> wrote in message
> news:npFDb.4186$QH1.3100@news.get2net.dk...
> > How do I write VBA that assigns selects my database record - like I
would
> do
> > manually by right-clicking the linked shape and pick the record. I know
> > whick record I am looking for because it is the shape's ID - as I have
> > exported all my records to the database.
> >
> >
>
>


0
chuck4097 (19)
12/17/2003 8:19:48 PM
Reply:

Similar Artilces:

Combo box list selection based on earlier selection by user
HI, I have a form that has a combo box 1 (Product) that reads a the Product table and has a unique id attached to each product (RO#). There is a second combo box 2 that is RO#. Now what I would like to do is when a user selects a Product in combo box 1, the system should lookup the Product selected from combo box 1 and upload the corresponding RO# in the combo box 2 list. Now I am using both combo boxes as Unbound and in the combo box 2 I have the two columns Product and RO# - in the Criteria row of RO# I have the following: Like IIf([Forms]![xa_f_lookup]![RO#]=" ",[Forms]![x...

Run report on multi selected records.
I try to make a report for a custom entity that works like the Account Summary: let's say that it's Customer's Inquiry Summary for entity Customer's Inquiry I made the report so that I'm able to run the report on Customer's Inquiry Form. But when I select multi records in the list of Customer's Inquiry and run report, only one record is show in one page of the the report. I would like to have the selected records appear in the report with each record on each page. How can I do this? ...

Struggles w/ Survey Database
I'm trying to put together a database for a Customer Service survey. I have 6 questions on the survey. Each question could be answered as Strongly agree, Agree, Neutral, Disagree or Strongly disagree. So far I have multiple tables set up - tblQuestions - QuestionID (auto), Question tblAnswers - AnswerID (auto), ResponseID, QuestionID, Answer tblResponses - ResponseID (auto), QuestionID, AnswerID, and a few others If I use a query that pulls these tables together in a query - the query result is blank. I think it's because there is no data yet to display. I'm fronting a user ...

Recovery Storage Group error when trying to add database
Running Exchange 2003, SP1, native mode on Windows 2003 I have created a recovery storage group, and when I right click on it to add the database to recover, I get the following error: The search filter cannot be recognized. Facility: Win32 ID no: 8007203e Exchange System Manager I have verified that AD has synced. Any ideas? Hi, The problem is that in the distinguished name of the database there is a single parenthesis without its match. Examples of this would include: cn=Mailbox Store 1 (SG1,cn=First Storage Group,.... cn=Mailbox Store 1 (SG2),cn=Second Storage Group (TestServer,cn...

Set Records Per Page Default
Hi, I'm new to CRM (version 4.0) and have been asked by the boss if it is possible to default the "records per page" option to 250 for all new users rather than the usual 50. I've been through three books now (Microsoft Dynamics CRM 4 for Dummies, Step by Step Microsoft Dynamics CRM 4.0 and Working with Microsoft Dynamics CRM 4.0) and while they all mention that 50 is the default, none of them mentions a way of changing that. Does anyone here know of a way of changing the default? Thanks, Tony. As far as I know there is no default setting for all users. -- htt...

Can't select objects in Excel 2007
I'm trying to create a form in Excel 2007, and although I can manipulate, copy & paste controls (check boxes, etc) I can't select multiple objects to align them, etc. I've checked on-line help (and have followed the instructions), and other websites, but no one seems to have indicated a problem. It is extremely cumbersome and I need a solution. Any ideas? Thanks in advance, Jim Berglund I know this is about a year too late, but it may help others who have stumbled across this page looking for similar help. On the Home tab, in the Editing group, click Find & Select....

Lot Selection not Showing when I select PO on Receiving Entry
Usually, the Lot selection screen would pop up when I select a PO at the Line Detail of the Receivings Entry, now it does not! And GP will let items post without a lot number! It seems as if a setting has changed. Any ideas anyone? Any help is appreciated. Thanks, R Are you sure the item is marked to track lots? This wiould be set item by item on the Item Maintenance Options window. -- Richard L. Whaley Author / Consultant / MVP 2006-2008 Documentation for Software Users Get our Free Tips and Tricks Newsletter and check out our books at http://www.AccoladePublications.com &q...

Import CSV file and add data to records
I've seperated my three questions to keep this organized. Basically I am importing a CSV file using an open dialog box..... Now, my already existing table has 5 fields, and my CSV file has 4 fields. Before the data is imported, is there a way to create a popup window asking the user to enter the date that the CSV file was generated and use that date as the fifth field for all of the new records being added from the CSV file? I hope I explained this question the right way. Please let me know if it isnt clear. if you want reliable ETL then you shoudl move to SQL Server and use DTS or BCP...

changing value of cell by dbl click without vba?
how can i get excel to change the value of a cell from a list by double clicking on it. e.g. cell has value "cat" then dbl clicking it changes it to dog, then to mouse and repeats with cat again.... of course, i want to know how to do this without vba/macros. No can do -- Don Guillett SalesAid Software donaldb@281.com "ntl.news.com" <asdasd@asdasd.asda> wrote in message news:dcOff.20342$8R6.12143@newsfe1-gui.ntli.net... > how can i get excel to change the value of a cell from a list by double > clicking on it. e.g. cell has value "cat" the...

Company database from within Dexterity
Hi, Is there a way to know what the company database is within Dexterity (i.e., via a SanScript function, or something like that)? I thought of using PassThrough SQL and doing "select top 1 db_name from DYNAMICS..DB_Upgrade where db_name <> 'DYNAMICS'" but am wondering if there is a better way. I can't hardcode a database name because this needs to be generic for different clients. Thanks in advance. 'Intercompany ID' of globals will hold the value of the company DB. -- dlothspe[MSFT]@online.microsoft.com This posting is provided "AS IS"...

Select contact then hangs
Hi, please help. I have a user that when she selects a contact using To: in a new email, after selecting 2, it closes outlook??. Spec is W2kSP4\office2k with all windows updates and office updates installed. Profile has been deleted and re-created, plus i have set up personal folders and moved contacts into there, and set that folder as a default, but makes no difference. Please help. ...

Selecting rows from various sheets
Hi all, I have several sheets with a few columns in each. One colum in each sheet has a unique value. Most of these unique values are th same in each sheet but not all. Is there any way that I can set up new sheet that will have the unique value in column 1 and th corresponding column values frommeach sheet beside it. For example Sheet 1 aa 1 1 1 bb 2 2 2 cc 3 3 3 Sheet 2 aa 4 4 cc 5 5 Result aa 1 1 1 4 4 bb 2 2 2 cc 3 3 3 5 5 Thanks alot, Sha -- sha ----------------------------------------------------------------------- shav's Profile: http...

select text in Calendar
I'm working on a calendar in Publisher. I'm adding text into a cell by spacing down 1 point, then typing in 8 points. Doing fine until April. At that time, I can only select cells (whole days). It will not let me select the text. Help is no help. Any hints out there. Did I accidentally select something to do this? Bonnie Have you added a picture to the cell or a shape? If you have send it to the back, make the cell no fill and try again. -- Mary Sauer MSFT MVP http://office.microsoft.com/ http://msauer.mvps.org/ news://msnews.microsoft.com "GoBonnieGo" <GoB...

Have Stores Create Records in HQ
Is it possible to have the stores databasse create records in the HQ dbase and not the other way around? For eg. Sometimes clients forget when they get new products to create it in HQ then send out to stores. Merci We have a utility to allow you to create an item simultaneousely at store and in HQ. Contact m efor more detail. Afshin Alikhani - [afshin@retailrealm.co.uk] CEO - Retail Realm "SIDSolutions" wrote: > Is it possible to have the stores databasse create records in the HQ dbase > and not the other way around? For eg. Sometimes clients forget when they get &g...

Can COMPILE ON DEMAND result database corruption?
Is it a known issue?Vladimir Cvajniga: COMPILE ON DEMAND is ON.David W. Fenton: Turn it OFF and you'll have less corruption.See David W. Fenton's post (March 4 th 2007 14:55) in the thread "Frequent Access 2003 corruption that cannot be repaired". Hello, Tom,MS guys seem that they ignore some recommendations... even from their colleagues. ;-(It's poor programming-language-design if it enables you to omit basics of programming.Luckily, I'm comming from Pascal-programmer-group so that I always declare variables. But to avoid problems I always check this setting in VB &a...

macro to filter data based on selected data
Hi, I am looking for a macro that requests input of a reference code and then a date and then filters the data in my spreadsheet based on this criteria. I am using excel 2007. Any help with this will be greatly appreciated. You can probably record a macro while doing it manually and then clean it up and add input boxes to ask the question or input your variable in a cell and use that. If all else fails, If desired, send your file to my address below. I will only look if: 1. You send a copy of this message on an inserted sheet 2. You give me the newsgroup and the ...

Link select with a blast
I have Win 7 Home Premium, x64. Quite often, when I select a link, a mouse pointer changes to a palm with a blast. I understand, the palm is the standard mouse pointer for link select, but what is the blast? What it indicates? -- Ilya Zeldes Fort Myers, Florida Hi Ilya, I suspect that this is being caused by a tracking program. Run something like Ad-Aware and see if it indicates a tracking company. If so, you can delete it, however, it might prevent you from accessing that particular website. Dave "Ilya Zeldes" wrote in message news:7A6FF9B1-5512-44...

Deleting duplicate records 01-21-10
I populated a table using an Append query. I created a duplicate records query using the Wizard. There are 20000 records. Now I need to delete the duplicates out of this query. How do I do that? this may be a duplicate post, im not seeing my first one. anyways, instead of deleting those duplicate records, lets just grab all the records that are not duplicates. (an unmatched query). do a LEFT JOIN from your main table to your duplicate table/query on primary keys. Choose your primary key from the DUPLICATE table, and set the criteria to Is Null. This will pull ALL Recor...

How can I tell is a posted Invoice is voided via database?
I have 2 invoices in Great Plains. Both were posted, but one was voided after is was posted. In the sales inquiry I see the voided transaction with a * next to the work open telling me it is voided. When I compare the 2 order rows in great plains SELECT TOP 1000 * FROM SOP30200 WHERE (SOPNUMBE = '1115060') OR (SOPNUMBE = '1127570a') I do not see anything different other than the dates an dollar amounts. How am I supposed to know what invoice is voided and what is not? SELECT * FROM SOP30200 WHERE VOIDSTTS = 1 Best regards, -- MG.- Mar...

Counting number of records based on criteria
Hello, (Try again to get the question in the google-groups. Perhaps not pushed on the send button). For counting records as expression in a report in ms.access I'm using =count(*) which shows all records. Now I also want to know how many of them has registered a specific data in a specific field. I'm trying to use =count([Field1]="999") to count how many of the selection reported has registered data 999. This option isn't work. Can somebody give me the correct solution. thanks, Johan The 999 needs to go in the criteria for the query driving the...

Select Case in a Change Event
Hi, I am trying to use a worksheet Change Event to trap changes to specific columns. depending on which column is chnaged by the user, the value in another ciolumn will be altered; so, changes in either column O or P will update column Q, changes in either column T or U will update column V and changes in column Z or AA will update column AB. What I can't figure out is the Select Case bit (where I've got the shouted question below). Here's what I've put together, any comments would be much appreciated. Private Sub Worksheet_Change(ByVal Target As Range) ...

Select Records based another table...
This may be very elementary, but i can't wrap my brain around it. I have tried to dummy it down as much as i can for myself, with plans of adapting it into something working. I have three tables that look like the following: Tbl 1: ProdID A B C 1 $1 $2 $3 2 $4 $5 $6 3 $7 $8 $9 Tbl 2: RmNum ProdID 1 3 1 2 2 1 2 2 Tbl 3: RmNum Style 1 A 2 C Relationships are: [tbl1 ProdID] ------ [tbl2 ProdID] [tbl2 RmNum] ...

Great Plains
Hello any one out there knows a comprhensive database backup plan for GreatPlains or could guide me to a documnet how to do this? Thanks, elmo You have two options and I recommend both of them. You can either get backup software that is SQL aware and can backup open SQL databases or you can create a maintenance plan that SQL itself runs to create DOS files on the hard drive that your backup software can pick up and move to tape or an external drive. You want to put together a rotation plan of several tapes/drives that are used once each for a week, then 5 sperate tapes for Fridays, ...

Combo Box to display only "active" records
Hi, I have a combo box based on a list of records in table. Overtime I may want to "de-activate" (Employee.Active=No) records in the list so that a user can longer chose it from the list, but I don't want previously selected records from list to be affected. I added a WHERE Employee.Active=Yes condition to the row source. My drop-down list no longer displays inactive records, but when I look at previous entries the record displayed is also blank. How do I only get this to apply to new records being created? Thanks Yes, that's a common scenario, Nancy. One ...

Multi-Select List Box Does Not Retain Selected Items
I created an Outlook Form in 2003. But when I select items in the list box they do not remain select when I select another control on the form. Any suggestions? Did you bind the list box to a keywords field? -- Sue Mosher, Outlook MVP Author of Microsoft Outlook Programming - Jumpstart for Administrators, Power Users, and Developers http://www.outlookcode.com/jumpstart.aspx "kaykay" <anonymous@discussions.microsoft.com> wrote in message news:276dd01c4638d$bd5af590$a501280a@phx.gbl... > I created an Outlook Form in 2003. But when I select > items i...