How to Set More than One Table Default Values from a Form

  • Thread starter Moscat via AccessMonster.com
  • Start date
M

Moscat via AccessMonster.com

Here I am reaching new frontiers and need some feedback and possible guidance.
I have a situation where when inputing information, the value of certain
fields remain the same. Due to the extensive number of fields in the form,
setting the value of these fields to its own default value will help in the
efficiency of inputing information. However, not all the time the selected
fields remain with the same value. Just for clarification purposes, I am
using the Table as the source for the default values.

For this, I have created an unbounded Form with unbounded fields and labels
that will list the available fields where the default value can be changed.
In this form, I have the unbounded field called DGroupName where I type the
new value I want to have a default. Since some fields are strings (in this
case), if I want to keep them Empty, I will input 'None' in DGroupName. If no
information is inputed, there is no change to the current value in its
default value.

Private Sub btnSubmit_Click()

Dim cnn As ADODB.Connection
Dim strSQL, strDefault As String

Set cnn = CurrentProject.Connection

If Me.DGroupName = "None" Then
strDefault = Empty
strSQL = "ALTER TABLE RoomData ALTER COLUMN GroupName varchar(50)
Default"
'strSQL = strSQL & strDefault
cnn.Execute strSQL, , dbFailOnError
MsgBox "Default for GroupName set to Null."
Set cnn = Nothing
ElseIf Not (IsNull(Me.DGroupName)) Then
strDefault = Me.DGroupName
strSQL = "ALTER TABLE RoomData ALTER COLUMN GroupName varchar(50) Default
"
strSQL = strSQL & strDefault
cnn.Execute strSQL, , dbFailOnError
MsgBox "Default for GroupName set to " & strDefault & "."
Set cnn = Nothing
End If

End Sub

The good news is that the code below works, but is only limited to one field.
I am looking for help or guidance in how to modify it to execute more than
one field instead of repeating the IF statement for every field. Is there's a
way?

Thanks in advance.
 

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