Setting vb actions based on the value in a field 
Author Message
 Setting vb actions based on the value in a field

Here's what I am trying to do:

I want to open two different forms depending on whether or
not data exists Field A in the first Record of Table TEST.

The problem is that I have no idea how to check the value
of a field in VBA code. Another thing that might be an
issue is that Field A is required, so if there is no value
in Field A, there are no records in Table TEST.



Wed, 11 Aug 2004 01:17:17 GMT  
 Setting vb actions based on the value in a field
You could do something like this:

Sub OpenForm()

    Const conTableName As String = "TEST"
    Const conFormName1 As String = "Form1"
    Const conFormName2 As String = "Form2"

    Dim db As DAO.Database
    Dim rs As DAO.Recordset

    Set db = CurrentDb()
    Set rs = db.OpenRecordset(conTableName)

    If rs.BOF And rs.EOF Then
'       You're only in here if there are NO
'       records in conTableName, so open FORM1:
        DoCmd.OpenForm conFormName1
    Else
'       You're only in here if there ARE records
'       in conTableName, so open FORM2:
        DoCmd.OpenForm conFormName2

'       However, if you want to test for a specific
'       value in [Field A], then do this instead:
        If rs.Fields("Field A") = "Josh" Then
            DoCmd.OpenForm conFormName2
        End If
    End If
End Sub

Geoff



Thu, 12 Aug 2004 01:10:33 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. Moving a field on a report, based on value of another field

2. Pass values from FORM fields to another page without a SUBMIT action

3. How to set form field value through VB ?

4. How to set form field value through VB ?

5. table.field value calculated based on query

6. sorting records from 1 table into several based on a field value

7. Setting a value based on Date.

8. Assigning Rank and Points based on a field value

9. SaveAs Filename based on Form Field Value

10. VB3: Setting listbox based on value of other listbox

11. Openfile based on value in a field

12. How do I set values in a VBControlExtender based control

 

 
Powered by phpBB® Forum Software