Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Microsoft Office > Access and Access VBA > Access VBA
|
Access VBA Discuss using VBA for Access programming.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Access VBA section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old June 1st, 2006, 11:27 AM
Authorized User
 
Join Date: May 2006
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
Default

This is the amended code:

Option Compare Database
Option Explicit

Dim NICode As String
Dim rs As ADODB.Recordset
Dim cn As ADODB.Connection

Dim strSQL As String

Set cn = Application.CurrentProject.Connection
Set rs = New ADODB.Recordset
NICode = "txtLetter"

strSQL = "SELECT " & NICode & "1a, " & NICode & "1b, " & NICode & "1c, " & NICode & "1d & NICode & "1g & NICode & "1h FROM WorkPlace NI Breakdown"

rs.Open strSQL, cn

If Not (rs.EOF And rs.BOF) Then
   MsgBox rs.Fields(NICode & "1a")
   MsgBox rs.Fields(NICode & "1b")
   MsgBox rs.Fields(NICode & "1c")
   MsgBox rs.Fields(NICode & "1d")
   MsgBox rs.Fields(NICode & "1g")
   MsgBox rs.Fields(NICode & "1h")


End If
rs.Close
cn.Close

Set rs = Nothing
Set cn = Nothing

 
Old June 1st, 2006, 11:33 AM
Friend of Wrox
 
Join Date: Oct 2004
Posts: 564
Thanks: 0
Thanked 4 Times in 4 Posts
Default

Alright, we're getting close. A couple of changes (ignore the *'s they just indicate the lines I have changed)

Option Compare Database
Option Explicit

*Private Sub cmdRun_Click()

Dim NICode As String
Dim rs As ADODB.Recordset
Dim cn As ADODB.Connection

Dim strSQL As String

Set cn = Application.CurrentProject.Connection
Set rs = New ADODB.Recordset
NICode = "txtLetter"

*strSQL = "SELECT " & NICode & "1a, " & NICode & "1b, " & NICode & "1c, " & NICode & "1d & NICode & "1g & NICode & "1h FROM [WorkPlace NI Breakdown]"

rs.Open strSQL, cn

If Not (rs.EOF And rs.BOF) Then
   MsgBox rs.Fields(NICode & "1a")
   MsgBox rs.Fields(NICode & "1b")
   MsgBox rs.Fields(NICode & "1c")
   MsgBox rs.Fields(NICode & "1d")
   MsgBox rs.Fields(NICode & "1g")
   MsgBox rs.Fields(NICode & "1h")


End If
rs.Close
cn.Close

Set rs = Nothing
Set cn = Nothing

*End Sub

Mike
EchoVue.com
 
Old June 2nd, 2006, 02:23 AM
Authorized User
 
Join Date: May 2006
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
Default

That has cleared the compile error. I am now receiving an error: Run Time Error '13' Type Mismatch. Which refers to line:

Set cn = Application.CurrentProject.Connection






Similar Threads
Thread Thread Starter Forum Replies Last Post
Displaying data in two columns peterh ASP.NET 2.0 Basics 11 January 29th, 2008 11:08 AM
Mapping columns and then copying data Roshanjoshi2001 Excel VBA 0 December 10th, 2007 11:37 AM
data selection and mapping with dropdownlist gagansharma7 ASP.NET 1.0 and 1.1 Basics 0 June 27th, 2006 11:41 AM
Data Report: Columns Against Rows bemular VB How-To 0 January 6th, 2005 12:52 AM
Getting the data in columns - like Pivot Table merguvan Access VBA 4 February 29th, 2004 02:31 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.