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: 7
Default running script when workbook opens problems

Hi,

I have a worksheet that accesss a database and displays the selected
record on the worksheet. The user selects the record by a msform
combobox which is populated with the ID of every record available. At
the moment I can only get the combobox to poulate when I press an
msForm command button. The code behind this button adds items to the
combobox.Both MSForm objects are on the worksheet not in a form.
What I would like to happen is for the combobox to be populated when I
open the workbook. To do this I put the code behind the refresh command
button in workbook_open() event. But I'm getting problems :o(

Because several scripts refresh the combobox e.g when a new record is
added/deleted etc I created a function 'ListRecipeCodes'
The input to the function is the combobox so the code behind the button
is:

ListRecipeCodes cboRecSel (where cboRecSel is the name of mycombobox)


ByRef argument Type mismatch error. Now I think I'm getting this error
because the sheet with the combobox isn't activated yet, so I've tried
putting Sheet(1).select before thee refresh code but I'm still getting
the error.

Can anyone help me please?

Thanks in advance.

Rich

Just in case my list fuction is the problem here it is:

Public Function ListRecipeCodes(combobox As Object)

Dim AdoCon As ADODB.Connection
Dim AdoRs As ADODB.Recordset
Dim strSQL As String
Dim strError


combobox.Clear
Application.Cursor = xlWait

strSQL = "SELECT DISTINCT " & ctsTblRecipe & "." & ctsNcRecipe &
ctiRecCodePos
strSQL = strSQL & " From " & ctsTblRecipe
strSQL = strSQL & " ORDER BY " & ctsTblRecipe & "." & ctsNcRecipe &
ctiRecCodePos

'Debug.Print strSQL

' Open the connection.
Set AdoCon = New ADODB.Connection
AdoCon.ConnectionString = ctsDB
AdoCon.Open

' Set the command text.
Set AdoRs = New ADODB.Recordset
AdoRs.Open strSQL, AdoCon, adOpenKeyset, adLockPessimistic,
adCmdText

AdoRs.MoveFirst

' Populate ComboBox with list of Recipe codes
Do Until AdoRs.EOF = True

If AdoRs(0) < "" Then
combobox.AddItem AdoRs(0)
End If

AdoRs.MoveNext
Loop

lbTidy:

AdoRs.Close
Set AdoRs = Nothing
Set AdoCon = Nothing
Application.Cursor = xlDefault

Exit Function

ErrorHandler:

strError = "List Recipe Codes Error"
strError = strError & _
Chr(10) & _
Chr(10) & "Error Number: " & Err & _
Chr(10) & "Error Description: " & Error()

MsgBox strError, vbInformation
Resume lbTidy

End Function

 
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
Problems in running a macro in another workbook dhatul Excel Discussion (Misc queries) 3 January 20th 06 08:01 AM
Running a script while editing a cell clayton Excel Discussion (Misc queries) 8 December 15th 05 10:24 PM
Personal workbook opens when Excel opens SheriTingle Excel Discussion (Misc queries) 2 March 30th 05 12:22 AM
running vbs script from vba? John Gunn Excel Programming 1 November 13th 04 01:08 AM
Running a VB Script Sofia Katchi Excel Programming 2 July 17th 03 03:22 PM


All times are GMT +1. The time now is 05:40 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"