Solved

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

Posted on 2001-06-20
4
141 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

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
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…

760 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now