Which field was used? (1 Viewer)

dcobau

Registered User.
Local time
Tomorrow, 01:16
Joined
Mar 1, 2004
Messages
124
G'day,

I have an unbound form that I want to use for adding records to one of a number of different tables according to the user needs. I do this by hiding/displaying different fields for different data (eg. Type of activity, Contact name). The Save button would have code that saves the data to the appropriate table (ie. Type of activity to tblActivities, etc). The problem I have is to detecting which field was made visible. So far I have the following code:

Private Sub cmdSave_Click()

Select Case ctl

Case "txtTitle"

If Me!txtTitle.Visible = True Then

MsgBox "title" ' Message to be replaced with proper code later

End If

Case "txtActivity"

If Me!txtActivity.Visible = True Then

MsgBox "activity" ' Message to be replaced with proper code later

End If

End Select

End Sub

When I press the save button nothing seems to happen. Any ideas?

thanks

Dave
 

pono1

Registered User.
Local time
Today, 08:16
Joined
Jun 23, 2002
Messages
1,186
Since you'll probably have many controls on your form, some relevant, others not, create a naming system so you can identify the controls that interest you. For example, use "CmdSave" as a common prefix for the controls you want to test.

Roughly...

Code:
   Dim ctl As Control
   Dim MyVisibleCtl As String
   
   For Each ctl In Me.Controls
      If left(ctl.name,7) = "CmdSave" Then
        If ctl.visible = True Then
  	    MyVisibleCtl = ctl.name
            Exit For
        End If
      End If
   Next ctl
   
   Select Case MyVisibleCtl
   
      Case "CmdSaveX"
         
         'Do this.
      
      Case "CmdSaveY"
        
         'Do that.
      
      Case "CmdSaveZ"
      
        'Do other.
      
   End Select

Regards,
Tim
 

ecniv

Access Developer
Local time
Today, 16:16
Joined
Aug 16, 2004
Messages
229
Another way is to use a group selection at the top... By this I mean the option groups, so the user selects which records to look at from here, then you code the save button to check the frame value (access) or the option selected (vb/vba excel etc).

Also, if you know what the user wants to enter, can you not store that in the form opening variables or in a variable held on the forms module, then use that when saving?


Vince
 

dcobau

Registered User.
Local time
Tomorrow, 01:16
Joined
Mar 1, 2004
Messages
124
Which field was used

thanks for both replies, will check them out later.

Dave
 

Users who are viewing this thread

Top Bottom