PDA

View Full Version : Coding of userform



musicexpress
05-07-2007, 06:13 AM
Thanks to Ken Puls for bringing me into this wonderful VBA forum. A really eye-opening forum with lotsa gurus here. :thumb:thumb:thumb

Recently have written some VBA code (via Macro Recorder) and modified it to process files and outputs as a standard Excel workbook.

Basically the daily CSV file (file1) is checked via a masterfile (file2) and the script outputs as a nicely tabulated results.

Program worked nicely. Went onto create a simple userform to replicate the process.

I have more or less created the codes for Browse1, Browse2, Process and Cancel buttons.

Basically the user only needs to input 2 files to process it.

The Process button has to be disabled (greyed-out) until the 2 files are specified. (apologies for not able to hotlink the snapshot here, due to newbie status:help)

Pseudocode is as shown:


Public flag1, flag2 As Boolean

Private Sub CommandBrowse1_Click()

' gets file1
' set flag1 = True if file1 is gotten, else flag1 = False

End Sub

Private Sub CommandBrowse2_Click()

' gets file2
' set flag2 = True if file2 is gotten, else flag2 = False

End Sub

Private Sub CommandProcess_Click()

' checks if flag1 AND flag2 are both true, Process button is enabled and executes

End Sub

Private Sub CommandCancel_Click()

' closes Userform and exits

End Sub

Private Sub TextBoxFile1_Change()

' displays the path and name of file1.
' how to disable cursor, as user need not enter the path?

End Sub

Private Sub TextBoxFile2_Change()

' displays the path and name of file2.
' disable cursor, as user need not enter the path?

End Sub

Private Sub CheckBox1_Click()

' how to get the value of the checkbox?

End Sub


Any kind advises/tips/ will be most appreciated. Many thanks all for taking the time to read.

musicexpress
05-07-2007, 03:26 PM
Any kind souls to advise?

lucas
05-07-2007, 04:19 PM
I can maybe help a little with this.
first you have to disable the command button when the form loads so you need a userform initialize statment for the userform:
something like this:
Private Sub Userform_Initialize()
CommandProcess_Click.Enabled = False
End Sub
Then you need an if..then...else statment in each of the textboxes. since you used psuedo code for your example I will just give you an example that is used with a combobox and I'm pretty sure you can figure it out...hope this helps:
If ComboBox1.Value <> "" And ComboBox2.Value <> "" And ComboBox3.Value <> "" Then
CommandButton1.Enabled = True
Else
CommandButton1.Enabled = False
End If