Defualt Text in an Input Box

G

Greg Maxey

Hi,

I might be wrapping myself around an axle here but I am trying to figure out
how to make the defualt text displayed in a input box match the last input
entered.

In my AutoNew macro, I have the following:

Dim oForm As Document
Dim SN As String

Set oForm = ActiveDocument

SN = InputBox("Enter student's name", "SN", " ")
oForm.Variables("SN").Value = SN

This provides a blank space to fill in a name to set a document varialbe.

In my AutoOpen macro, I have the following:

Sub AutoOpen()
Dim oForm As Document
Dim SN As String
Dim UpdateSN As VbMsgBoxResult

Set oForm = ActiveDocument
UpdateSN = MsgBox("Do you want to change or update the student's name?",
vbYesNo)
If UpdateSN = vbYes Then
SN = InputBox("Enter changes or updates to student's name", "SN", " ")
oForm.Variables("SN").Value = SN
End If

I am trying to get the student's name to appear as the defualt if the user
choose to update or change the students name. I can't figure out what needs
to go between the " ". It tried & SN & but that returned & SN &.

Can this be done?
 
J

Jezebel

You need to retrieve the saved value into a variable, and use that:

Dim OldSN as string

OldSN = oForm.Variables("SN")
SN = InputBox("Enter student's name", "SN", OldSN)
 
G

Greg Maxey

Jezebel,

I just figured that out!!!

Dim DefaultSN

Set oForm = ActiveDocument
DefaultSN = oForm.Variables("SN").Value
UpdateSN = MsgBox("Do you want to change or update the student's name?",
vbYesNo)
If UpdateSN = vbYes Then
SN = InputBox("Enter changes or updates to student's name", "SN",
DefaultSN)
oForm.Variables("SN").Value = SN


I have just finished a pair of backflips. Thanks for your help!!
 

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