Solved

View is not useable after Appending (Access, ADOX, VB)

Posted on 2001-06-20
4
150 Views
Last Modified: 2010-05-02
Running Win '98, Access 97, VB

I'm using the included Function to create views.

Problem 1)
After creating a view, I open Access and check it out.
It look ok, but reports an error when executed.
After touching the SQL (inserting a blank, replacing an 'a' by an 'a') the view works perfect. ?

Problem 2)
Normal views can be access by the following code, but not the view created by the function I include.

dim ViewSql as string
    ....
    ....
    Set DBcmd = dbcat.Views(ViewName).Command
   
    ViewSQL = Trim(DBcmd.CommandText)

Can anybody help?
Am I missing a Property somewhere?

-------------------
Private Function ViewCreate(ViewName As String, ViewSQL As String) As Boolean
Dim dbcat As ADOX.Catalog
Dim DBcmd As ADODB.Command
       
' create view (xxx)

    ViewCreate = False
   
    On Error GoTo ErrorHandling
   
    Set dbcat = New ADOX.Catalog
    Set dbcat.ActiveConnection = ConnectionString
    Set DBcmd = New ADODB.Command

    DBcmd.CommandText = ViewSQL
   
    dbcat.Views.Append ViewName, DBcmd
    dbcat.Views.Refresh
   
    Set dbcat = Nothing
    Set DBcmd = Nothing
   
    ViewCreate = True
   
    Exit Function

ErrorHandling:
    MsgBox ERR.Number & " " & ERR.Description
   
End Function
0
Comment
Question by:abekke
  • 2
4 Comments
 
LVL 1

Expert Comment

by:mariab_
ID: 6210737
Hi,

try to create the view this way:

where ViewSQL is for example: "CREATE VIEW titles_view AS SELECT title, type, price, pubdate FROM titles"

Private Function ViewCreate(ViewName As String, ViewSQL As String) As Boolean

Dim DBcmd As ADODB.Command
       
' create view (xxx)

   ViewCreate = False
   
   On Error GoTo ErrorHandling

   Set DBcmd.ActiveConnection = ConnectionString

   DBcmd.CommandText = ViewSQL
   DBcmd.Execute ViewSQL
   
   Set DBcmd = Nothing
   
   ViewCreate = True
   
   Exit Function

ErrorHandling:
   MsgBox ERR.Number & " " & ERR.Description
   
End Function
0
 
LVL 1

Expert Comment

by:mariab_
ID: 6210744
ops!

without the line "DBcmd.CommandText = ViewSQL" :)))

Regards :))
0
 
LVL 5

Accepted Solution

by:
ianouii earned 300 total points
ID: 6213153
> Problem 1)
> After creating a view, I open Access and check it out.
> It look ok, but reports an error when executed.
> After touching the SQL (inserting a blank, replacing
> an 'a' by an 'a') the view works perfect. ?

it's most likely when u create your view, the string that is being passed in isn't correct. try to check on the view string to ensure it's ok & workable when execute. U can use Query Analyzer to help u.

> Problem 2)
> Normal views can be access by the following code, but
> not the view created by the function I include.

This might bcoz of your view error. if your view isn't working properly, when invoke it, ofcoz u'll encounter error. try to resolve your 1st problem, I'm sure your 2nd problem can be easily resolved.

good luck.
0
 

Author Comment

by:abekke
ID: 6224498
The Sql contained an error!

This is what I found out:
----- if I use

  DBcmd.commandText = ViewSql
  DBcat.Views.Append ViewName, DBcmd
  DBcat.Views.Refresh

The view is created even if it contains an error

------ while using
  DBcmd.CommandText = "CREATE VIEW " & ViewName & " AS " & ViewSql
  DBcmd.Execute

The View is validated

Thanks to both of you!

This is the code I ended up with:
-------------------
Private Function ViewCreate(ViewName As String, ViewSQL As String) As Boolean
Dim DBcmd As ADODB.Command
Dim TotalViewSql As String

    ViewCreate = False
   
    On Error GoTo ErrorHandling
   
    Set DBcmd = New ADODB.Command
    Set DBcmd.ActiveConnection = ConnectionString
   
    TotalViewSql = "CREATE VIEW " & ViewName & " AS " & ViewSQL
    DBcmd.CommandText = TotalViewSql
    DBcmd.Execute
   
    Set DBcmd = Nothing
   
    ViewCreate = True
   
    Exit Function

ErrorHandling:
    MsgBox ERR.Number & " " & ERR.Description
   
End Function
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Access 2013 combo box not working 3 51
Exit a vb6 apps when a calling it apps closes 15 52
VBA - If Bookmark = "XXBOOKMARKXX" then 15 40
Set WorkSheet  not Working 9 41
The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

860 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question