PDA

View Full Version : File with VBA form errors on save



PrestonWhitn
03-10-2010, 10:19 PM
I have a file that opens a form when the file is opened. That form inserts the field date into bookmarks in the document when the OK button is pressed. the form code is below and the document code is below that. The problem I am having is that when I try and close out the file it always errors and wont let me save the file with the updated fields. Any suggestions what I might be doing wrong.

Private Sub btnOK_Click()
Dim varModelNo As String
If opt800 = True Then varModelNo = "800"
If opt1800 = True Then varModelNo = "1800"
If opt3600 = True Then varModelNo = "3600"
If opt5400 = True Then varModelNo = "5400"
If opt7000 = True Then varModelNo = "7000"
If opt10000 = True Then varModelNo = "10000"
Application.ScreenUpdating = False
With ActiveDocument
.Bookmarks("QuoteNo").Range.Text = txtQuoteNo.Value
.Bookmarks("RevNo").Range.Text = txtRevNo.Value
.Bookmarks("ClientName").Range.Text = txtClientName.Value
.Bookmarks("QuoteDateLong").Range.Text = txtQuoteDate.Value
.Bookmarks("PreparedBy").Range.Text = txtPreparedBy.Value
.Bookmarks("ModelNo").Range.Text = varModelNo
End With
Application.ScreenUpdating = True
Unload Me
End Sub
Private Sub UserForm_Initialize()
txtQuoteNo.Value = True
End Sub


Document Code
Private Sub Document_Open()
BioScruQuote.Show
End Sub

SamT
03-11-2010, 07:10 AM
If txtQuoteNo is a TextBox control, then


Private Sub UserForm_Initialize()
txtQuoteNo.Value = "True"
End Sub



The Value of a TextBox is the text (Variant) in its text edit region.

fumei
03-12-2010, 10:10 AM
1. It is generally better to use the data type you want. If this is a textbox, then use:

txtQuote.Text
rather than .Value.

However, this may not be your problem. You state that you have a problem with saving.
The problem I am having is that when I try and close out the file it always errors and wont let me save the file with the updated fields.Please, when you mention errors it is helpful if you state what the error actually is. What is the error? What does it say? You do not have the code you are using regarding saving, so how can we see what the problem may be? The code you posted is not relevant to the problem you state you have. Nothing there indicates any issue with saving the file.