Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Microsoft Access VBA question -- Same problem

Posted on 2009-07-08
6
Medium Priority
?
492 Views
Last Modified: 2013-12-06
A question from user Jeanniem has not been actually answered, and i noticed that it is closed.
I'm having the same problem  (I'm using msaccess 2003)

  Can't construct a simple SQL on MS-ACESS VB. I'm using ODBC on an AS400.
   I'm having the same runtime error as Jeanniem.

   For some reason it is not permitting the use of SELECT Clause.

   However it is accepting this string while i'm experimenting.

   SQLStr = "LIB.Table1, LIB.Table2 Where Table1.FLD1 = 1 And Table1.FLD1 = Table2.FLD2"

  This query is accepted. I think it is assuming that it is in (Select *) default. Notice that i put the join in the where clause (a workaround 'And Table1.FLD1 = Table2.FLD2')

   @Jeanniem --> could you try this and give me any feedback? thanks
Set Cnxn = New ADODB.Connection
Set rst1 = New ADODB.Recordset
strCnxn = "Provider='IBMDA400';Data Source='myDSN';User d='';Password='';"
Cnxn.Open strCnxn
 
SQLStr = "Select * From LIB.Table1 Inner join LIB.Table2 On Table1.FLD1 = Table2.FLD2 Where FLD1 = 1"
 
rst1.Open SQLStr, Cnxn, adOpenKeyset, adLockOptimistic, adCmdTable

Open in new window

0
Comment
Question by:belbenj
6 Comments
 
LVL 85

Assisted Solution

by:Scott McDaniel (Microsoft Access MVP - EE MVE )
Scott McDaniel (Microsoft Access MVP - EE MVE ) earned 600 total points
ID: 24812268
Remove the adCmdTable argument and see what happens.

0
 
LVL 16

Expert Comment

by:Chuck Wood
ID: 24813743
1. Is FLD1 a field with the same name in Table1 and Table2? If so, you need to qualify it (Table1.FLD1)
2. Shouldn't it be "Select * From LIB/Table1 Inner join LIB/Table2 ..." for DB2 on AS400?
-chuck wood
0
 

Expert Comment

by:Jeanniem
ID: 24814462
When I had this problem, it was solved with help from Gary the IT.....

He suggested I do a debug.print on my SQL statement - when I did that it showed me that I didn't have spaces betweeen some of the words and when I fixed that, it worked.  It looks like your SQLstr is correct, but it wouldn't hurt to do a debug.print just in case.
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 36

Accepted Solution

by:
Gary Patterson earned 1400 total points
ID: 24816563
The IBMDA400 provider defaults to the SQL naming convention (lib.table).  You can switch to System naming convention (lib/table) if you like by adding the "Naming Convention=1" option to your connection string.  It defaults to "0", so your table names are formatted OK here.

As observed by LMSConsulting, adCmdTable option needs to go.  This option causes the ADO provider to generate a query for you, and is not compatible with an SQL statement being provided in the SOURCE parameter.

Now, what is the exact error message that you are getting?

A few additional notes:

1) IBMDA400 is an OLE DB provider.  OLE DB Providers do not use ODBC data sources, so if "myDSN" is an ODBC data source name, you need to change it to the name of your AS/400 (IP address, FQDN, etc.).

2) I don't know if you have any duplicated field names between your tables (are these really the table and field names, or did you substitute generic names?  Post the real field and table names if possible), but it is a good practice to get in the habit of using correlation names for your tables:

Select * From LIB.Table1 as T1 Inner join LIB.Table2 T2 On T1.FLD1 = T2.FLD2 Where T1.FLD1 = 1

Note that each field reference is qualified with the correlation name.

3) If you continue to have trouble, drop down to adOpenStatic and adLockReadOnly and see if your query works.  Post back if you need to change these parameters to make it work (are you planning to update, and do you plan to move bback and forth in your results in a way where you need to see records that change while you are running your application?

4) Test your SQL using the Navigator program that comes with IBM Client Access, navigate to your AS/400 -> Databases -> right click your database, and select Run SQL Scripts.  Test your query here until it works - you'll get easier access to detailed error messages.  Use Connection -> JDBC Setup to set your preferred connection settings (like the naming format).  You can also use the green-screen utility STRSQL to test SQL statements (that is my preferred tool).
 
- Gary Patterson

0
 

Author Comment

by:belbenj
ID: 24820126
@Jeanniem: Oops, sory i thought your issue was not resolved. though your last post was "Your definately right about the space, but it still throws the following error". sorry

adCmdTable - is indeed the porblem. thanks. my query is working and i can use joins now. thanks a lot

about "myDSN" -  my bad I'm actually using the IP address not DSN

I also prefer using lib/table format though i don't know where to insert the "Naming Convention=1" parameter in my connection string. can you guys help out? is there any reference docs on all the parameters that can be inserted in the connection string?

myConString = "Provider='IBMDA400';Data Source='XX.XXX.X.XXX';User Id='';Password='';"

Notice that I left User Id and password blank. so that it will pop up the login access to AS400 via client access. but when i click the cancel on the popup. I get msgbox that "user cancelled!" or something. how can i catch that error? thanks all in advance
0
 
LVL 36

Assisted Solution

by:Gary Patterson
Gary Patterson earned 1400 total points
ID: 24825945
Put it anyplace you like in the connection string.  Order doesn't matter.

OLE DB Driver documentation is included as part of the Help that comes with Client Access Programmer's Toolkit - an optionally-installable Client Access component.

You handle this error like any other in VBA:  Either let the default handler catch it (that is what is happening now), or provide your own error handling.  See the example below.

- Gary Patterson









Set Cnxn = New ADODB.Connection
Set rst1 = New ADODB.Recordset
strCnxn = "Provider='IBMDA400';Data Source='myAS400';User id='';Password='';Naming Convention=1;"
 
On Error Resume Next    'We will handle our own errors
Cnxn.Open strCnxn
If Err.Number = 0 Then
    MsgBox "Connection succeeded"
    Cnxn.Close
Else
    MsgBox "Connection failed with error: " & Err.Number & " - " & Err.Description
    Err.Clear
End If
On Error GoTo 0        ' Switch back to default error handler

Open in new window

0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

Code that checks the QuickBooks schema table for non-updateable fields and then disables those controls on a form so users don't try to update them.
Explore the ways to Unlock VBA Project Password Excel 2010 & 2013 documents. Go through the article and perform the steps carefully to remove VBA Excel .xls file.
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…

571 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