get data to and from a text/combo box on user form

EDUCATED MONKEY

Board Regular
Joined
Jul 17, 2011
Messages
218
Window XP Professional Office 2003 ie8<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /><o:p></o:p>
<o:p> </o:p>
<o:p> </o:p>
In this project I have a user form, “UserForm1” which initially I start up by using the forms Activate method<o:p></o:p>
e.g.<o:p></o:p>
<o:p> </o:p>
Private Sub Worksheet_Activate()<o:p></o:p>
Worksheets("DataInput").Range("A2").Select ‘set active cell on worksheet DataInput<o:p></o:p>
UserForm1.Show<o:p></o:p>
'Call UserForm_Initialize<o:p></o:p>
<o:p> </o:p>
End Sub<o:p></o:p>
<o:p> </o:p>
This works fine except that if I leave the Call UserForm_Initialize in I get run error 424 <o:p></o:p>
And this line is .AddItem "GOOD" highlight please see section of code block 1<o:p></o:p>
<o:p> </o:p>
If however I put the exact same code behind a command button it works fine ? so I know at least that code block 1 works correctly and initialises all the combo boxes as required<o:p></o:p>
<o:p> </o:p>
Now I move on to the next odd think I need help with, on this same user form I have a button defined as BtnPreviousRecord the required action here being to load the values on a particular row on the DataInput worksheet again if I put the code behind the command button to do so it works fine, however if I put the exact same code in a macro and try to call the macro by clicking the button I get run error 424 please see code block 2<o:p></o:p>
<o:p> </o:p>
I am assuming that I calling these macros incorrectly or something along those lines so please if you can tell what the calling conventions are <o:p></o:p>
Rich (BB code):
code block 1  part of <o:p></o:p>
<o:p> </o:p>
Sub UserForm_Initialize()<o:p></o:p>
'<o:p></o:p>
' FillComboBox Macro<o:p></o:p>
' Macro recorded <?xml:namespace prefix = st1 ns = "urn:schemas-microsoft-com:office:smarttags" /><st1:date Month="9" Day="7" Year="2011">07/09/2011</st1:date> by development2<o:p></o:p>
'<o:p></o:p>
' Keyboard Shortcut: Ctrl+Shift+F<o:p></o:p>
'<o:p></o:p>
    With cbogc    ' Add values to combo box general condition<o:p></o:p>
        .AddItem "GOOD"<o:p></o:p>
        .AddItem "FAIR"<o:p></o:p>
    End With<o:p></o:p>
<o:p> </o:p>
End Sub 


Rich (BB code):
code block 2<o:p></o:p>
<o:p> </o:p>
Private Sub BtnPreviousRecord_Click()<o:p></o:p>
Dim LValue2 As String<o:p></o:p>
'need to add the no jpeg rootine<o:p></o:p>
Dim LValue3 As String<o:p></o:p>
Dim LValue4 As String<o:p></o:p>
Dim LValue5 As String<o:p></o:p>
Dim MyString As String<o:p></o:p>
Dim NewString As String<o:p></o:p>
Dim MyString2 As String<o:p></o:p>
Dim MyString1 As String<o:p></o:p>
Worksheets("DataInput").Range("A2").Select<o:p></o:p>
<o:p> </o:p>
<o:p> </o:p>
TextBox13DIGIT_ISBN.Value = ActiveCell.Value<o:p></o:p>
TextBox13DIGIT_ISBN_HY.Value = ActiveCell.Offset(0, 1)<o:p></o:p>
TextBox10DIGIT_ISBN.Value = ActiveCell.Offset(0, 2)<o:p></o:p>
TextBox10DIGIT_ISBN_HY.Value = ActiveCell.Offset(0, 3)<o:p></o:p>
TextBoxNAME_1.Value = ActiveCell.Offset(0, 4)<o:p></o:p>
'TextBoxNAME_I.Value = ActiveCell.Offset(0, 5)<o:p></o:p>
TextBoxNAME_2.Value = ActiveCell.Offset(0, 5)<o:p></o:p>
TextBoxTITLE.Value = ActiveCell.Offset(0, 6)<o:p></o:p>
TextBoxHEIGHT.Value = ActiveCell.Offset(0, 7)<o:p></o:p>
TextBoxWIDTH.Value = ActiveCell.Offset(0, 8)<o:p></o:p>
TextBoxDEPTH.Value = ActiveCell.Offset(0, 9)<o:p></o:p>
TextBoxWEIGHT.Value = ActiveCell.Offset(0, 10)<o:p></o:p>
TextBoxYEAR.Value = ActiveCell.Offset(0, 11)<o:p></o:p>
TextBoxEDITION.Value = ActiveCell.Offset(0, 13)<o:p></o:p>
TextBoxPUBLISHER.Value = ActiveCell.Offset(0, 14)<o:p></o:p>
TextBoxFORMAT.Value = ActiveCell.Offset(0, 21)<o:p></o:p>
TextBoxBookType.Value = ActiveCell.Offset(0, 17)<o:p></o:p>
TextBoxCost.Value = ActiveCell.Offset(0, 12)<o:p></o:p>
TextBoxlocation.Value = ActiveCell.Offset(0, 20)<o:p></o:p>
TextBoxJpeg.Value = ActiveCell.Offset(0, 22)<o:p></o:p>
cbogc.Value = ActiveCell.Offset(0, 18)<o:p></o:p>
cboGENRE.Value = ActiveCell.Offset(0, 16)<o:p></o:p>
ComboBoxAdditional.Value = ActiveCell.Offset(0, 17)<o:p></o:p>
TextBoxSYNOPSIS.Value = ActiveCell.Offset(0, 15)<o:p></o:p>
MyString = ".jpg"<o:p></o:p>
MyString1 = ActiveCell.Offset(0, 4).Value<o:p></o:p>
MyString2 = ActiveCell.Offset(0, 5).Value<o:p></o:p>
NewString = MyString1 & " " & MyString2<o:p></o:p>
LValue5 = LCase(NewString)<o:p></o:p>
LValue3 = ActiveCell.Offset(0, 22).Value<o:p></o:p>
<o:p> </o:p>
LValue2 = "I:\PICTURES OF BOOKS\" & LValue3 & MyString<o:p></o:p>
<o:p> </o:p>
Image1.Picture = LoadPicture(LValue2)<o:p></o:p>
LValue4 = "I:\authorpics\" & LValue5 & MyString<o:p></o:p>
<o:p> </o:p>
 If Len(Dir(LValue4)) Then 'check to see if there is a jpeg<o:p></o:p>
  Image2.Picture = LoadPicture(LValue4)<o:p></o:p>
 End If<o:p></o:p>
<o:p> </o:p>
'Call GetData<o:p></o:p>
<o:p> </o:p>
End Sub<o:p></o:p>
 

Excel Facts

When did Power Query debut in Excel?
Although it was an add-in in Excel 2010 & Excel 2013, Power Query became a part of Excel in 2016, in Data, Get & Transform Data.

Forum statistics

Threads
1,224,583
Messages
6,179,673
Members
452,937
Latest member
Bhg1984

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top