Excel properties

K

Kevin

Hi all,

I used some code to force people to fill in the properties in word.
Then i adapted the code to excel as follows:
Private Sub CommandButton1_Click()
If (ComboBox1.Value = "") Then
MsgBox ("You need to fill in the department.")
ElseIf InStr(1, TextBox2.Value, "Fill in the author",
vbTextCompare) <> 0 Then
MsgBox ("You need to fill in the author.")
ElseIf (TextBox2.Value = "") Then
MsgBox ("You need to fill in the author.")
ElseIf InStr(1, TextBox2.Value, "Fill in the keywords",
vbTextCompare) <> 0 Then
MsgBox ("You need to fill in the keywords.")
ElseIf (TextBox2.Value = "") Then
MsgBox ("You need to fill in the keywords.")
ElseIf InStr(1, TextBox3.Value, "Fill in the title",
vbTextCompare) <> 0 Then
MsgBox ("You need to fill in the title.")
ElseIf (TextBox3.Value = "") Then
MsgBox ("You need to fill in the title.")
ElseIf InStr(1, TextBox4.Value, "Fill in the subject",
vbTextCompare) <> 0 Then
MsgBox ("You need to fill in the subject.")
ElseIf (TextBox4.Value = "") Then
MsgBox ("You need to fill in the subject.")
Else
Call WriteProp("Department", ComboBox1.Value)
Call WriteProp("Author", TextBox1.Value)
Call WriteProp("Keywords", TextBox2.Value)
Call WriteProp("Title", TextBox3.Value)
Call WriteProp("Subject", TextBox4.Value)
Dialogs(xlDialogSaveAs).Show
UserForm1.hide
End If
End Sub
Private Sub UserForm_Initialize()
Dim cn As ADODB.Connection, rs As ADODB.recordset

TextBox1 = ReadProp("Author")
TextBox2 = ReadProp("Keywords")
TextBox3 = ReadProp("Title")
TextBox4 = ReadProp("Subject")
ComboBox1.Value = ReadProp("Department")
ComboBox1.ColumnCount = 1
Set cn = New ADODB.Connection
cn.Open "Provider=Microsoft.JET.OLEDB.4.0; data
source=\\server3\psi global\company_databases\Tec_Amendments.mdb;"
Set rs = New ADODB.recordset
With rs
.Open "select department from department order by department",
cn, , , adCmdText
End With
rs.MoveFirst
Do While Not rs.EOF
ComboBox1.AddItem rs.Fields(0).Value
rs.moveNext
Loop
rs.Close
Set rs = Nothing
cn.Close
Set cn = Nothing
End Sub

But when the user clicks the button he refreshes the dialog (all empty
fields), doesn't show the save as dialog and hangs the whole document.
Does anyone know why this happens? It works fine in word.
 
K

Kevin

The code in the previous message works fine in the vb editor after
slight change. But it doesn't work in the document itself. It shows
the dialog but then it shows the dialog again instead of the save as
dialog. After that it closes the dialog. (It seems like the savedialog
became my dialog)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top