Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 310
Default SQL statement not working

Help!!!! I'm trying to load a combo box on my Excel form by getting the
records from an Access database thru an SQL statement . For some reason it
doesn't like my SQL statement. I get "No value given for one or more required
parameters. I have tried several different methods. What am I doing wrong and
what works! Thanks for you help!

Private Sub cboBWContractNumber_Click()
Dim UsageTracking As ADODB.Connection
Dim objCommand As ADODB.Command
Dim recordset As ADODB.recordset
Dim i As Integer
Dim strSQLEquipCommodity As String
'At this point, cboContractNumber is populated with values _
When cboBWContractNumber is selected _
Display cboEquipmentCommodity for that contract number _
Filter records and fill combo box with selection _
Create new sub for Get Commodity DSR's
____________________________________________
'Create Connection String Method 1

Set UsageTracking = New ADODB.Connection
With UsageTracking
.ConnectionString = _
"Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=" &
"\\bsrvfp04\shared\PLM\database\UsageTracking. mdb" & "; "
.Mode = adModeShareDenyNone
.Open
End With


Application.EnableEvents = True
If cboBWContractNumber.Value < "" Then
frmDSRHeader.cboEquipmentCommodity.Visible = True

'Create Command Object for query

Set objCommand = New ADODB.Command
objCommand.ActiveConnection = UsageTracking

'Load SQL string into Command object

objCommand.CommandText = "SELECT tblDSRCommodity.BWProjectNumberID,
tblDSRCommodity.COA, [Code of Accounts].Description " & _
"FROM tblDSRCommodity INNER JOIN [Code of
Accounts] ON tblDSRCommodity.COA=[Code of Accounts].COA " & _
"WHERE tblDSRCommodity.BWProjectNumberID =
Me!cboBWContractNumber.value ORDER BY tblDSRCommodity.COA;"
'Execute the statement

Set recordset = objCommand.Execute '(Options:=adCmdText)
__________________________________________________ _________
Set recordset = New ADODB.recordset Method 2
With recordset
.ActiveConnection = UsageTracking
.Open "SELECT tblDSRCommodity.BWProjectNumberID,
tblDSRCommodity.COA, [Code of Accounts].Description " & _
"FROM tblDSRCommodity INNER JOIN [Code of Accounts] ON
tblDSRCommodity.COA=[Code of Accounts].COA " & _
"WHERE tblDSRCommodity.BWProjectNumberID =
Me!cboBWContractNumber ORDER BY tblDSRCommodity.COA;"
.Close
End With

Set recordset = New ADODB.recordset
recordset.CursorType = adOpenStatic
recordset.LockType = adLockReadOnly
recordset.Options = adCmdText
recordset.Open strSQLEquipCommodity, UsageTracking
recordset.MoveFirst


With Me.cboEquipmentCommodity
.Clear
.ColumnCount = 2
Do
.AddItem
.List(i, 0) = recordset![COA]
.List(i, 1) = recordset![Description]
i = i + 1
recordset.MoveNext
Loop Until recordset.EOF
End With
End If
Set recordset = Nothing
UsageTracking.Close
Set UsageTracking = Nothing
End Sub
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 310
Default SQL statement not working

FSt1,

Thanks for your response. Its happening on the Open statement OR when it
actually tries to run the sql.

"FSt1" wrote:

hi
i may be going out on a limb here but.......
on what line in your code is the error occuring?

Regards
FSt1
p.s. i think you are making this WAY more compllicated than it needs to be.

"Michelle" wrote:

Help!!!! I'm trying to load a combo box on my Excel form by getting the
records from an Access database thru an SQL statement . For some reason it
doesn't like my SQL statement. I get "No value given for one or more required
parameters. I have tried several different methods. What am I doing wrong and
what works! Thanks for you help!

Private Sub cboBWContractNumber_Click()
Dim UsageTracking As ADODB.Connection
Dim objCommand As ADODB.Command
Dim recordset As ADODB.recordset
Dim i As Integer
Dim strSQLEquipCommodity As String
'At this point, cboContractNumber is populated with values _
When cboBWContractNumber is selected _
Display cboEquipmentCommodity for that contract number _
Filter records and fill combo box with selection _
Create new sub for Get Commodity DSR's
____________________________________________
'Create Connection String Method 1

Set UsageTracking = New ADODB.Connection
With UsageTracking
.ConnectionString = _
"Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=" &
"\\bsrvfp04\shared\PLM\database\UsageTracking. mdb" & "; "
.Mode = adModeShareDenyNone
.Open
End With


Application.EnableEvents = True
If cboBWContractNumber.Value < "" Then
frmDSRHeader.cboEquipmentCommodity.Visible = True

'Create Command Object for query

Set objCommand = New ADODB.Command
objCommand.ActiveConnection = UsageTracking

'Load SQL string into Command object

objCommand.CommandText = "SELECT tblDSRCommodity.BWProjectNumberID,
tblDSRCommodity.COA, [Code of Accounts].Description " & _
"FROM tblDSRCommodity INNER JOIN [Code of
Accounts] ON tblDSRCommodity.COA=[Code of Accounts].COA " & _
"WHERE tblDSRCommodity.BWProjectNumberID =
Me!cboBWContractNumber.value ORDER BY tblDSRCommodity.COA;"
'Execute the statement

Set recordset = objCommand.Execute '(Options:=adCmdText)
__________________________________________________ _________
Set recordset = New ADODB.recordset Method 2
With recordset
.ActiveConnection = UsageTracking
.Open "SELECT tblDSRCommodity.BWProjectNumberID,
tblDSRCommodity.COA, [Code of Accounts].Description " & _
"FROM tblDSRCommodity INNER JOIN [Code of Accounts] ON
tblDSRCommodity.COA=[Code of Accounts].COA " & _
"WHERE tblDSRCommodity.BWProjectNumberID =
Me!cboBWContractNumber ORDER BY tblDSRCommodity.COA;"
.Close
End With

Set recordset = New ADODB.recordset
recordset.CursorType = adOpenStatic
recordset.LockType = adLockReadOnly
recordset.Options = adCmdText
recordset.Open strSQLEquipCommodity, UsageTracking
recordset.MoveFirst


With Me.cboEquipmentCommodity
.Clear
.ColumnCount = 2
Do
.AddItem
.List(i, 0) = recordset![COA]
.List(i, 1) = recordset![Description]
i = i + 1
recordset.MoveNext
Loop Until recordset.EOF
End With
End If
Set recordset = Nothing
UsageTracking.Close
Set UsageTracking = Nothing
End Sub

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 310
Default SQL statement not working

The WHERE statement is where it messing up!

WHERE tblDSRCommodity.BWProjectNumberID =
Me!cboBWContractNumber.value


BWProjectNumberID = numeric
cboBWContractNumber = Alphanumeric

How can I convert cboBWContractNumber = numeric?

"Michelle" wrote:

FSt1,

Thanks for your response. Its happening on the Open statement OR when it
actually tries to run the sql.

"FSt1" wrote:

hi
i may be going out on a limb here but.......
on what line in your code is the error occuring?

Regards
FSt1
p.s. i think you are making this WAY more compllicated than it needs to be.

"Michelle" wrote:

Help!!!! I'm trying to load a combo box on my Excel form by getting the
records from an Access database thru an SQL statement . For some reason it
doesn't like my SQL statement. I get "No value given for one or more required
parameters. I have tried several different methods. What am I doing wrong and
what works! Thanks for you help!

Private Sub cboBWContractNumber_Click()
Dim UsageTracking As ADODB.Connection
Dim objCommand As ADODB.Command
Dim recordset As ADODB.recordset
Dim i As Integer
Dim strSQLEquipCommodity As String
'At this point, cboContractNumber is populated with values _
When cboBWContractNumber is selected _
Display cboEquipmentCommodity for that contract number _
Filter records and fill combo box with selection _
Create new sub for Get Commodity DSR's
____________________________________________
'Create Connection String Method 1

Set UsageTracking = New ADODB.Connection
With UsageTracking
.ConnectionString = _
"Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=" &
"\\bsrvfp04\shared\PLM\database\UsageTracking. mdb" & "; "
.Mode = adModeShareDenyNone
.Open
End With


Application.EnableEvents = True
If cboBWContractNumber.Value < "" Then
frmDSRHeader.cboEquipmentCommodity.Visible = True

'Create Command Object for query

Set objCommand = New ADODB.Command
objCommand.ActiveConnection = UsageTracking

'Load SQL string into Command object

objCommand.CommandText = "SELECT tblDSRCommodity.BWProjectNumberID,
tblDSRCommodity.COA, [Code of Accounts].Description " & _
"FROM tblDSRCommodity INNER JOIN [Code of
Accounts] ON tblDSRCommodity.COA=[Code of Accounts].COA " & _
"WHERE tblDSRCommodity.BWProjectNumberID =
Me!cboBWContractNumber.value ORDER BY tblDSRCommodity.COA;"
'Execute the statement

Set recordset = objCommand.Execute '(Options:=adCmdText)
__________________________________________________ _________
Set recordset = New ADODB.recordset Method 2
With recordset
.ActiveConnection = UsageTracking
.Open "SELECT tblDSRCommodity.BWProjectNumberID,
tblDSRCommodity.COA, [Code of Accounts].Description " & _
"FROM tblDSRCommodity INNER JOIN [Code of Accounts] ON
tblDSRCommodity.COA=[Code of Accounts].COA " & _
"WHERE tblDSRCommodity.BWProjectNumberID =
Me!cboBWContractNumber ORDER BY tblDSRCommodity.COA;"
.Close
End With

Set recordset = New ADODB.recordset
recordset.CursorType = adOpenStatic
recordset.LockType = adLockReadOnly
recordset.Options = adCmdText
recordset.Open strSQLEquipCommodity, UsageTracking
recordset.MoveFirst


With Me.cboEquipmentCommodity
.Clear
.ColumnCount = 2
Do
.AddItem
.List(i, 0) = recordset![COA]
.List(i, 1) = recordset![Description]
i = i + 1
recordset.MoveNext
Loop Until recordset.EOF
End With
End If
Set recordset = Nothing
UsageTracking.Close
Set UsageTracking = Nothing
End Sub

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
IF Statement not working steve12173 Excel Worksheet Functions 7 June 18th 09 06:44 PM
SQL statement not working FSt1 Excel Programming 0 February 26th 09 11:45 PM
VBA SQL Statement not working brittonsm Excel Programming 1 June 7th 08 05:04 PM
IF statement not working TJAC Excel Discussion (Misc queries) 2 January 13th 06 01:08 PM
If statement not working excelnut1954 Excel Programming 6 December 15th 05 09:38 PM


All times are GMT +1. The time now is 10:33 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"