A 2010 VBA if then

Dick7Access

Dick S
Local time
Today, 11:35
Joined
Jun 9, 2009
Messages
4,325
On my cmdNext button I have the following code, but nothing works. What am I doing wrong?
If Me.txtDateComp.Text = "" Then
Me.txtDateComp.Visible = True
End If

I have tried, "null","is null", NullI, Is null,“false”,“”, [null]
 
Dick,

As crazy as it seems:

Me.txtDateComp.Text

Is only valid in the OnChange event.

Use the .Value or nothing.

hth,
Wayne
 
to test for a null your syntax will be;

Code:
If IsNull(Me.txtDateComp) Then
     Me.txtDateComp.Visible = True
End If

Please also check out this thread ;)
 
Nether example is working with all kinds of variations. Should I have mention in my first post that "txtDateComp" is a date/time field? would that make a difference?
 
Try;
Code:
If IsNull(Me.txtDateComp) Or Me.txtDateComp = "" Then
     Me.txtDateComp.Visible = True
End If
 
Try;
Code:
If IsNull(Me.txtDateComp) Or Me.txtDateComp = "" Then
     Me.txtDateComp.Visible = True
End If

Not working! Here is the entire code for that cmd. Maybe something else before it is screwing it up.

Code:
   Private Sub cmdNext_Click()

On Error GoTo Err_Handler
 
DoCmd.GoToRecord , , acNext
 
ccmdNext_Exit:
Exit Sub
 
Err_Handler:
If Err.Number = 2105 Then
   MsgBox "You have already reached the Last subscriber.", vbApplicationModal, "Bibles To You"
Else
   MsgBox Err.Description, vbExclamation, "Error #: " & Err.Number
End If
   Resume ccmdNext_Exit
   
  If IsNull(Me.txtDateComp) = "" Then     ' Or Me.txtDateComp
     Me.txtDateComp.Visible = True
End If
 
For starters you've put the code in the error handling section of the code, so it's not going to get fired, even if there is an error as it is below the Resume ccmdNext_Exit portion of the Error handling sub routine.

Additionally I don't recall presenting any code that looked like;
Code:
If IsNull(Me.txtDateComp) = ""
That just won't work.

Try;
Code:
Private Sub cmdNext_Click()

On Error GoTo Err_Handler
 
DoCmd.GoToRecord , , acNext

If IsNull(Me.txtDateComp)  Or Me.txtDateComp = "" then
     Me.txtDateComp.Visible = True
End If
 
ccmdNext_Exit:
Exit Sub
 
Err_Handler:
If Err.Number = 2105 Then
   MsgBox "You have already reached the Last subscriber.", vbApplicationModal, "Bibles To You"
Else
   MsgBox Err.Description, vbExclamation, "Error #: " & Err.Number
End If
   Resume ccmdNext_Exit

Although I'm not sure if you want to test that field before or after your move to the next record :confused:
 
For starters you've put the code in the error handling section of the code, so it's not going to get fired, even if there is an error as it is below the Resume ccmdNext_Exit portion of the Error handling sub routine.

Additionally I don't recall presenting any code that looked like;
Code:
If IsNull(Me.txtDateComp) = ""
That just won't work.

Try;
Code:
Private Sub cmdNext_Click()

On Error GoTo Err_Handler
 
DoCmd.GoToRecord , , acNext

If IsNull(Me.txtDateComp)  Or Me.txtDateComp = "" then
     Me.txtDateComp.Visible = True
End If
 
ccmdNext_Exit:
Exit Sub
 
Err_Handler:
If Err.Number = 2105 Then
   MsgBox "You have already reached the Last subscriber.", vbApplicationModal, "Bibles To You"
Else
   MsgBox Err.Description, vbExclamation, "Error #: " & Err.Number
End If
   Resume ccmdNext_Exit
Although I'm not sure if you want to test that field before or after your move to the next record :confused:

When I move to the next record I wanted the "txtDateComp" , I Have it now hidden intentionally, to become viable if the student had not returned his lesson. I had plan to put the same code in the previous cmd also.

I thought I had copied and paste the code (If IsNull(Me.txtDateComp) = "") from your post but maybe I am wrong, I will go back and check.

I am guessing that it should go right after the "docmd" is that correct?

Even tho I do these db for people for free I think I may have take on more than I can handle, but since I agreed to take the job I will keep studying.
 
For starters you've put the code in the error handling section of the code, so it's not going to get fired, even if there is an error as it is below the Resume ccmdNext_Exit portion of the Error handling sub routine.

Additionally I don't recall presenting any code that looked like;
Code:
If IsNull(Me.txtDateComp) = ""
That just won't work.

Ok, I went back over your post and can see what I did wrong. I add the last part of your post, the (= "") to the first part, (If IsNull(Me.txtDateComp)
 
(trivia) If you have seen the weather report for the northeast USA you have an idea why I now live in FL
 
No, it's a play on the old saying; "cold enough to freeze the balls off a brass monkey".

Stanthorpe+Brass+Monkey.jpg


So they'll be out looking for a welder to re-attach their ...

You follow, now ;)
 
Yes I have heard that expression many times, and have used it myself. I knew what you were jesting about. Your also inserted a pun but I wondered if you knew it.
 
Hey, my mouth still waters for those giant crayfish (crawdads) or wherever you folks call them. Can you put one in a compress file for me.

also send please send me a good link to study the if then. I have google it and have not come up with what I need. The other problem I am going to have with this client is that he has A2000 and some of my stuff 2010 won't work, but I may be able to get him to dish out a $100 bucks and come up to speed.
 
I'm not on my machine with Access '10, but I think you should be able to save back to an older version.

As for It Then try this link.
 

Users who are viewing this thread

Back
Top Bottom