Checking empty fields based on another textbox value (1 Viewer)

theDBguy

I’m here to help
Staff member
Local time
Yesterday, 18:21
Joined
Oct 29, 2018
Messages
21,467
It is not bringing me back to the code line when I click save... :confused:
Hi. Earlier, you said when you clicked on the Save button, you see the MsgBox we added. Are you saying when you click on the Save button now you're not seeing the MsgBox anymore? You did leave it there and simply set a break point to it, did you not?
 

Mackbear

Registered User.
Local time
Yesterday, 20:21
Joined
Apr 2, 2019
Messages
168
Hi. Earlier, you said when you clicked on the Save button, you see the MsgBox we added. Are you saying when you click on the Save button now you're not seeing the MsgBox anymore? You did leave it there and simply set a break point to it, did you not?

Yes I left the code for the message box and set a break point. it is now red but when I click on save it just shows the message box, that's it.
 

Micron

AWF VIP
Local time
Yesterday, 21:21
Joined
Oct 20, 2018
Messages
3,478
The break should be after or before the message.
 

theDBguy

I’m here to help
Staff member
Local time
Yesterday, 18:21
Joined
Oct 29, 2018
Messages
21,467
Yes I left the code for the message box and set a break point. it is now red but when I click on save it just shows the message box, that's it.
Hi. Can you please post a screenshot of the code with the break point set? Thank you.
 

Mackbear

Registered User.
Local time
Yesterday, 20:21
Joined
Apr 2, 2019
Messages
168
Hi. Can you please post a screenshot of the code with the break point set? Thank you.

Here it is, I also attached the DB now the on the main form click view then it will bring up another form and on that form click vendor reachout, that is where the problem is. I am not sure why it does not take me to debug screen anymore if there is a problem or error, it might for you but for me it does not do it anymore...
 

Attachments

  • pichelp.JPG
    pichelp.JPG
    28.9 KB · Views: 29
  • dbsample.zip
    1.2 MB · Views: 28

The_Doc_Man

Immoderate Moderator
Staff member
Local time
Yesterday, 20:21
Joined
Feb 28, 2001
Messages
27,172
Open the VBA screen to the code you want to break on. Put the mouse cursor in the column to the left of the actual code line on which you want to break. Click it once and you should see a red dot.

Once that dot is there, if you trigger something that should execute the code. It will break BEFORE it executes the line.

Let's look at the first part of your example.

Code:
Private Sub save_Click()

'check the always required fields
  [COLOR="Red"]If IsNull(Me.extdatevreachout) Or IsNull(Me.lfassessedvreachout) Or IsNull(waiverapprv) Or IsNull(reqmethod) Then[/COLOR]

  [COLOR="SeaGreen"]MsgBox "Please check empty fields", _
    vbCritical, _
    "Canceling Update"
    Me.extdatevreachout.SetFocus[/COLOR]
  Cancel = True
  Exit Sub

End If

I have highlighted two lines. If you put your breakpoint on the RED line, it should stop there every time you click the appropriate button. If you put your breakpoint on the GREEN line, it might not stop because of the prior IF statement for which the conditions might not be met. Therefore, it would appear to not break, when in fact you never get to the breakpoint due to program logic.

Therefore, when you say you tried to run the code but nothing happens... it could be because of breakpoint placement. If that doesn't apply, then it is also possible that your event routine isn't properly linked to that code.
 

Mackbear

Registered User.
Local time
Yesterday, 20:21
Joined
Apr 2, 2019
Messages
168
Open the VBA screen to the code you want to break on. Put the mouse cursor in the column to the left of the actual code line on which you want to break. Click it once and you should see a red dot.

Once that dot is there, if you trigger something that should execute the code. It will break BEFORE it executes the line.

Let's look at the first part of your example.

Code:
Private Sub save_Click()

'check the always required fields
  [COLOR="Red"]If IsNull(Me.extdatevreachout) Or IsNull(Me.lfassessedvreachout) Or IsNull(waiverapprv) Or IsNull(reqmethod) Then[/COLOR]

  [COLOR="SeaGreen"]MsgBox "Please check empty fields", _
    vbCritical, _
    "Canceling Update"
    Me.extdatevreachout.SetFocus[/COLOR]
  Cancel = True
  Exit Sub

End If

I have highlighted two lines. If you put your breakpoint on the RED line, it should stop there every time you click the appropriate button. If you put your breakpoint on the GREEN line, it might not stop because of the prior IF statement for which the conditions might not be met. Therefore, it would appear to not break, when in fact you never get to the breakpoint due to program logic.

Therefore, when you say you tried to run the code but nothing happens... it could be because of breakpoint placement. If that doesn't apply, then it is also possible that your event routine isn't properly linked to that code.


I tried putting the breakpoint on the line highlighted in Red. I tried to run it by clicking the button. Nothing happens.:banghead: I think may be there is something wrong with my VB, I never had debug errors recently, I just knew there was something wrong because it does not work.
 

Mackbear

Registered User.
Local time
Yesterday, 20:21
Joined
Apr 2, 2019
Messages
168
I think this part of the code is not working:

Dim LF As DAO.Recordset
Set LF = CurrentDb.OpenRecordset("tbl_LFrequests", dbOpenDynaset)
LF.AddNew
LF("entryid_LFinfo") = Me![entryid_vendreach]
LF("InvoiceCount") = Me![invcnt]
LF("WaiverApproved") = Me![waiverapprv]
LF("RequestMethod") = Me![reqmethod]
LF("DeclinedReason") = Me![declinedreason]
LF("CreditedAmount") = Me![creditamnt]
LF("CreditMethod") = Me![creditmethod]
LF("ExpDatetoCredit") = Me![expinvdatecredit]
LF("ReviewStatus") = "Open"
LF("ReqbyAP") = Environ("Username")
LF("ReqDate") = Date
LF("ReqDateTime") = Date + Time
LF("ReqWeek") = Me![wweek]
LF("ReqMonth") = Me![mmonth]

LF.Update
LF.close
Set LF = Nothing
DoCmd.close acTable, "tbl_LFrequests", acSaveYes



What is wrong with this?

:banghead:
 

theDBguy

I’m here to help
Staff member
Local time
Yesterday, 18:21
Joined
Oct 29, 2018
Messages
21,467
I tried putting the breakpoint on the line highlighted in Red. I tried to run it by clicking the button. Nothing happens.:banghead: I think may be there is something wrong with my VB, I never had debug errors recently, I just knew there was something wrong because it does not work.
Hi. I downloaded your file and found the issue why you can't step through your code. In the Current Database Options, you have unchecked the "Use Access Special Keys" checkbox. You probably did this to prevent users from hitting the F11 key to display the Navigation Pane because the F11 key is a "special key." Unfortunately, if F11 is a special key, the F8 is also a special key. If you hover your mouse over the "info" icon next to this option, it will show that this option affects "Pause Execution." So, while troubleshooting your database, put a check on this option and just take it back out before you deploy your app to your users.
 

Mackbear

Registered User.
Local time
Yesterday, 20:21
Joined
Apr 2, 2019
Messages
168
Hi. I downloaded your file and found the issue why you can't step through your code. In the Current Database Options, you have unchecked the "Use Access Special Keys" checkbox. You probably did this to prevent users from hitting the F11 key to display the Navigation Pane because the F11 key is a "special key." Unfortunately, if F11 is a special key, the F8 is also a special key. If you hover your mouse over the "info" icon next to this option, it will show that this option affects "Pause Execution." So, while troubleshooting your database, put a check on this option and just take it back out before you deploy your app to your users.


Thank you I will try it!
:)
 

Mackbear

Registered User.
Local time
Yesterday, 20:21
Joined
Apr 2, 2019
Messages
168
My only problem now is this:

this part works, it asks value for the 3 fields if the waiverapprv is YES
If Me.waiverapprv = "Yes" And IsNull(Me.creditamnt) Or IsNull(Me.creditmethod) Or IsNull(expinvdatecredit) Then

MsgBox "Please check empty fields", _
vbCritical, _
"Canceling Update"
Me.extdatevreachout.SetFocus
Cancel = True
Exit Sub


if the value is No, it still asked for values for the other 3 that is only applicable if the waiverapprv value is YES.
ElseIf Me.waiverapprv = "No" And IsNull(Me.declinedreason) Then

MsgBox "Please check empty fields", _
vbCritical, _
"Canceling Update"
Me.extdatevreachout.SetFocus
Cancel = True
Exit Sub
 

Mackbear

Registered User.
Local time
Yesterday, 20:21
Joined
Apr 2, 2019
Messages
168
Hope it helps...

It helped and I was able to correct most of the errors, I didn't know it would stop the debugging message, I was really having a hard time figuring out what could be the errors... Thank you for looking into it. Now I have another problem... the checking of fields, I am not sure if I structured the if conditions correctly.
 

Micron

AWF VIP
Local time
Yesterday, 21:21
Joined
Oct 20, 2018
Messages
3,478
Interesting and good to know. Way back I was going to suggest using the step button on the toolbar (probably not there by default) because F8 and F5 don't necessarily behave the same on every pc. On mine, I have to include the Fn key so I rarely use F8 over the toolbar button. I just figured it wouldn't apply, but I now suspect it would have at least allowed stepping through in this case.
 

Users who are viewing this thread

Top Bottom