Author Topic: ADO question  (Read 4644 times)

0 Members and 1 Guest are viewing this topic.

Jim Yadon

  • Guest
ADO question
« on: September 07, 2005, 09:43:38 PM »
I have been noodling over this one for days now. Can anyone help me out with this one?

I keep getting a 3265 error but the data is there. I can remove ITM# or DESC (along with the relevant SQL bulding syntax) and pull the data for one field but not both together. In the past it's been my SQL. I've tested it within the MDB though so I'm reasonably sure that's not it.

Here's the code -

Code: [Select]
Private Sub UserForm_Initialize()
    Call Populate2ComboWhere(cmbValueLisT, "c:\edbs\edbs.mdb", "ITM#", "DESC", "JOB DETAIL LIST", "JOB", "00-0000")
End Sub

Public Sub Populate2ComboWhere(objCombo As ComboBox, strDBase As String, strField1 As String, strField2 As String, strTable As String, strControlField As String, strControlData As String)
  Dim strSQL As String
  Dim objConn As ADODB.Connection
  Dim objRSet As ADODB.Recordset
  Set objConn = New ADODB.Connection
  objConn.ConnectionString = _
        "Provider=Microsoft.Jet.OLEDB.4.0;" & _
        "Data Source=" & strDBase & ";" & _
        "Persist Security Info=False"
  With objConn
  .Provider = "Microsoft.Jet.OLEDB.4.0"
  .mode = adModeReadWrite
  End With
  objConn.Open
  strSQL = "SELECT [" & strTable & "].[" & strField1 & _
                "],[" & strTable & "].[" & strField2 & _
                "] FROM [" & strTable & _
                "] WHERE [" & strTable & "].[" & strControlField & "]=""" & strControlData & _
                """ ORDER BY [" & strTable & "].[" & strField1 & "]"
  Set objRSet = objConn.Execute(strSQL, , adCmdText)
  Debug.Print strSQL
  Do Until objRSet.EOF
    objCombo.AddItem objRSet.Fields(CStr(strField1) & "~" & strField2)
    objRSet.MoveNext
  Loop
  objRSet.Close
  objConn.Close
End Sub

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: ADO question
« Reply #1 on: September 07, 2005, 09:47:29 PM »
Use single quotes instead of double quotes for string tests and terminate with a semicolon.

i.e. Select * from tablename where fieldname = 'some value';

/guess
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

Jim Yadon

  • Guest
Re: ADO question
« Reply #2 on: September 07, 2005, 10:02:45 PM »
Same result. Hmmm...

Here's the revised version what I'm using. It's a basic Access 2000 db BTW.

Code: [Select]
Private Sub UserForm_Initialize()
'    Call PopulateComboWhere(cmbValueLisT, "c:\edbs\edbs.mdb", "ITM#", "JOB DETAIL LIST", "JOB", "00-0000")
'    Call PopulateComboWhere(cmbValueLisT, "c:\edbs\edbs.mdb", "DESC", "JOB DETAIL LIST", "JOB", "00-0000")
    Call Populate2ComboWhere(cmbValueLisT, "c:\edbs\edbs.mdb", "ITM#", "DESC", "JOB DETAIL LIST", "JOB", "00-0000")
End Sub

Public Sub Populate2ComboWhere(objCombo As ComboBox, strDBase As String, strField1 As String, strField2 As String, strTable As String, strControlField As String, strControlData As String)
  Dim strSQL As String
  Dim objConn As ADODB.Connection
  Dim objRSet As ADODB.Recordset
  Set objConn = New ADODB.Connection
  objConn.ConnectionString = _
        "Provider=Microsoft.Jet.OLEDB.4.0;" & _
        "Data Source=" & strDBase & ";" & _
        "Persist Security Info=False"
  With objConn
  .Provider = "Microsoft.Jet.OLEDB.4.0"
  .mode = adModeReadWrite
  End With
  objConn.Open
  strSQL = "SELECT [" & strTable & "].[" & strField1 & _
                "],[" & strTable & "].[" & strField2 & _
                "] FROM [" & strTable & _
                "] WHERE [" & strTable & "].[" & strControlField & "]='" & strControlData & _
                "' ORDER BY [" & strTable & "].[" & strField1 & "]"
  Set objRSet = objConn.Execute(strSQL, , adCmdText)
  Debug.Print strSQL
  Do Until objRSet.EOF
    objCombo.AddItem objRSet.Fields(CStr(strField1) & "~" & strField2)
    objRSet.MoveNext
  Loop
  objRSet.Close
  objConn.Close
End Sub

Public Sub PopulateComboWhere(objCombo As ComboBox, strDBase As String, strField1 As String, strTable As String, strControlField As String, strControlData As String)
  Dim strSQL As String
  Dim objConn As ADODB.Connection
  Dim objRSet As ADODB.Recordset
  Set objConn = New ADODB.Connection
  objConn.ConnectionString = _
        "Provider=Microsoft.Jet.OLEDB.4.0;" & _
        "Data Source=" & strDBase & ";" & _
        "Persist Security Info=False"
  With objConn
  .Provider = "Microsoft.Jet.OLEDB.4.0"
  .mode = adModeReadWrite
  End With
  objConn.Open
  strSQL = "SELECT [" & strTable & "].[" & strField1 & "] FROM [" & _
            strTable & "] WHERE [" & strTable & "].[" & strControlField & "]='" & _
            strControlData & "' ORDER BY [" & strTable & "].[" & strField1 & "]"
  Set objRSet = objConn.Execute(strSQL, , adCmdText)
  Debug.Print strSQL
  Do Until objRSet.EOF
    objCombo.AddItem objRSet.Fields(strField1)
    objRSet.MoveNext
  Loop
  objRSet.Close
  objConn.Close
End Sub

Jürg Menzi

  • Swamp Rat
  • Posts: 599
  • Oberegg, Switzerland
Re: ADO question
« Reply #3 on: September 08, 2005, 02:40:22 AM »
How about:
Code: [Select]
objCombo.AddItem CStr(objRSet.Fields(strField1)) & "~" & CStr(objRSet.Fields(strField2))
A computer's human touch is its unscrupulousness!
MENZI ENGINEERING GmbH
Current A2k16... A2k24 - Start R2.18

Jim Yadon

  • Guest
Re: ADO question
« Reply #4 on: September 20, 2005, 12:51:17 PM »
Simple answer to my own question. Make sure the references are correct for the project you are working in. :doh: :ugly:

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: ADO question
« Reply #5 on: September 21, 2005, 06:29:07 AM »
Hi Jim

Just to see what the future holds ...

http://msdn.microsoft.com/netframework/future/linq/

C# 3.0 LINQ in action
C# 3.0 XLinq in action
C# 3.0 DLinq in action

the thought of the possibilities blew me away ..
The VB Versions are also available < I assume >
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: ADO question
« Reply #6 on: September 21, 2005, 07:42:48 AM »
Hi Jim

Just to see what the future holds ...

http://msdn.microsoft.com/netframework/future/linq/

C# 3.0 LINQ in action
C# 3.0 XLinq in action
C# 3.0 DLinq in action

the thought of the possibilities blew me away ..
The VB Versions are also available < I assume >

Very interesting and lol: "... Anders Hejlsberg, Chief randomizer on the C# development team ..."
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

Jim Yadon

  • Guest
Re: ADO question
« Reply #7 on: September 27, 2005, 12:12:27 PM »
Cool stuff!!!  :lol:  Thanks Kerry!