Results 1 to 5 of 5
  1. #1
    Heatshiver is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Dec 2011
    Posts
    128

    Question AndAlso equivalent in VBA?

    I have a piece of code that requires a logical operator like AndAlso in VB.net.


    I can circumvent this by creating another form, but I am trying to reuse forms where possible as there will be many more to add later.


    The code is a simple If statement with the first line involving both a DLookup for date validation and a second part checking if a field is locked (I've also tried enabled).




    I tried using the And operator, and it gives me an error to the DLookup part (and rightfully so).


    I just need the code to check to make sure both parts of the statement are true, and if not, to proceed with the rest of the code statements.

  2. #2
    Robeen is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    Mar 2011
    Location
    Tulsa, Oklahoma.
    Posts
    1,596
    Could you post the code here for us to see?

  3. #3
    Heatshiver is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Dec 2011
    Posts
    128
    If DLookup("Days", "tblDailyReport", "[Days] = #" & [End Date] & "#") Then
    'Do Nothing
    Else
    MsgBox "No report with that End Date has been filled out."
    Exit Sub
    End If

    At the moment I have duplicated the form and taken out this piece. This does work, but I would still like to figure out a way to skip over this somehow.

  4. #4
    Robeen is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    Mar 2011
    Location
    Tulsa, Oklahoma.
    Posts
    1,596
    The code is a simple If statement with the first line involving both a DLookup for date validation and a second part checking if a field is locked (I've also tried enabled).
    If I understand you correctly, you want:
    If
    [Days] = [EndDate]
    And
    Your_TextBox is Locked
    Then
    Do Something?
    Else
    Exit Sub

    Is that correct?

    If so . . .
    Will something like this work for you?
    Code:
    If DLookup("Days", "tblDailyReport", "[Days] = #" & [End Date] & "#") Then
        If Me.TextBoxName.Locked Then
              'Do Something
        End If
    Else
    MsgBox "No report with that End Date has been filled out."
    Exit Sub
    End If

  5. #5
    Heatshiver is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Dec 2011
    Posts
    128
    I tried that, but still get an error. I think the DLookup still expects an answer no matter what. I have to try to skip over it somehow.

    I am going to try something like this tomorrow and see what results I get:

    Dim b As Boolean
    If Me.[End Date].Locked = False Then b = (DCount("*", "tblDailyReport", "[Days] = #" & Me![End Date] & "#") > 0)
    If b Then
    'Do Nothing
    Else
    MsgBox "No report with that Start Date has been filled out."
    Exit Sub
    End If

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Oracle LAG Equivalent
    By OzzyMiner in forum Queries
    Replies: 2
    Last Post: 03-10-2011, 11:41 AM
  2. autecl*** for pcomm - I am looking for equivalent?
    By jasonarmey in forum Programming
    Replies: 0
    Last Post: 09-22-2010, 04:30 PM
  3. Equivalent MsAccess Query
    By noviceUser in forum Access
    Replies: 2
    Last Post: 09-18-2010, 06:03 AM
  4. Is there equivalent code in VBA?
    By techneophyte in forum Programming
    Replies: 4
    Last Post: 08-02-2010, 07:11 AM
  5. WeekdayName equivalent in 2000
    By sunnybrook in forum Queries
    Replies: 8
    Last Post: 07-14-2010, 10:47 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums