LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 411
Default Using DAO to write to textbox in userform

Hi

I've used the code below to successfully update a textbox on a
worksheet.

When I tried to call this from a command button on a userform, it
failed with the error compile error: user defined type not defined

on the Dim wspDefault As Workspace line.

I'm grateful for any suggestions.

Thanks,

Dan

Sub CreateRecordSet()

Dim oldDbName As String
***Dim wspDefault As Workspace
Dim dbsEAIQuote As Database
Dim strSQL As String
Dim strCompetitorPart As String
Dim strEAIPart As String
Dim rstFromQuery As Recordset

strCompetitorPart = Sheet1.TextBox1.Text
strEAIPart = Sheet1.TextBox2.Text


'Set the path to the database
oldDbName = "C:/My Documents/Quote/EAIQuote_be.mdb"

'Create a default workspace Object
Set wspDefault = DBEngine.Workspaces(0)

'Create a Database object
Set dbsEAIQuote = wspDefault.OpenDatabase(oldDbName)

'The SQL statement
strSQL = "SELECT tblCompetitorScrubbed.CompetitorNumber, " & _
"tblCompetitorScrubbed.EAIPartNumber FROM
tblCompetitorScrubbed " & _
"WHERE (tblCompetitorScrubbed.CompetitorNumber= '" &
strCompetitorPart & "')"

'Create a Snapshot Type Recordset from the SQL query
Set _
rstFromQuery = dbsEAIQuote.OpenRecordset(strSQL, dbOpenSnapshot)

'Show the number of fields returned
MsgBox "there are " & rstFromQuery.Fields.Count & _
" fields that were returned"

'Move to the last record in the recordset
rstFromQuery.MoveLast

'Put the EAI part number in textbox2
Sheet1.TextBox2.Value = rstFromQuery!EAIPartNumber
'Show the number of records returned
MsgBox "there are " & rstFromQuery.RecordCount & _
" records that were returned"

End Sub
 
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
fill userform textbox from userform listbox clik event GregJG[_21_] Excel Programming 3 December 7th 08 04:47 PM
Userform textbox help [email protected] Excel Programming 0 September 16th 06 10:57 PM
write to external workbook from userform nycdon Excel Programming 1 August 17th 05 06:36 PM
Write Contents of TextBox to new Workbook Andy Tallent Excel Discussion (Misc queries) 0 February 21st 05 11:45 AM
UserForm TextBox to ActiveSheet TextBox over 256 characters Dan E[_2_] Excel Programming 1 July 28th 03 07:36 PM


All times are GMT +1. The time now is 01:15 PM.

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

About Us

"It's about Microsoft Excel"