Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

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

Posted on 2001-06-20
4
Medium Priority
?
167 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 900 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

Tech or Treat!

Submit an article about your scariest tech experience—and the solution—and you’ll be automatically entered to win one of 4 fantastic tech gadgets.

Question has a verified solution.

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

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses

618 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