Repost, 1st one didn't go thru... Please Help! Form not listening to me

G

Gina Whipp

Hello All,

I have this on the Form_Unload event. What I want if both conditions are
true then ask the question. But if one or both of these conditions are true
then just close. I have tried the 3 condition below and none are working.
Can someone help me as to why it won't listen to me?

Thanks,
Gina Whipp

TRIED: If Form_sfrBoLDetail.Recordset.RecordCount > 0 Or Not
IsNull([cboBillOfLadingID]) Then Exit Sub

TRIED: If Form_sfrBoLDetail.Recordset.RecordCount > 0 And Not
IsNull([cboBillOfLadingID]) Then Exit Sub

TRIED: If Form_sfrBoLDetail.Recordset.RecordCount > 0 And
Me.cboBillOfLadingID < 0 Then Exit Sub


----- Balance of code----

Dim Msg, Style, Title, Response, MyString

Msg = "There are no lifts on this Bill of Lading, it will be deleted!
Is that what you want to do?"
Style = vbYesNo + vbQuestion + vbDefaultButton1
Title = "Delete"

Response = MsgBox(Msg, Style, Title)

If Response = vbYes Then
MyString = "Yes"
DoCmd.SetWarnings False
DoCmd.RunSQL "DELETE tblBillOfLading.bolBillOfLadingID FROM
tblBillOfLading WHERE (((tblBillOfLading.bolBillOfLadingID) =
[Forms]![frmBillOfLading]![txtBillOfLadingID]));"
DoCmd.RunSQL "UPDATE tblGetBillOfLadingID SET
tblGetBillOfLadingID.gbolBillOfLadingNumber = [gbolBillOfLadingNumber]-1,
tblGetBillOfLadingID.gbolBillOfLadingID = Val([gbolBillOfLadingID])-1 WHERE
(((tblGetBillOfLadingID.gbolBillOfLadingID)=[Forms]![frmBillOfLading]![cboBillOfLadingID])
AND
((tblGetBillOfLadingID.gbolCustomerID)=[Forms]![frmBillOfLading]![cboCustomerID]));"
DoCmd.SetWarnings True
Else
MyString = "No"
DoCmd.CancelEvent
End If
 
M

ManningFan

It's either being very naughty, or perhaps it is YOU who are not
listening to IT. I would put a break in the code and use the Immediate
window (or just mouse over the values) to see just what it thinks
cboBillOfLadingID and Form_sfrBoLDetail.Recordset.RecordCount are.
This usually gives critical insight into just what the form is
thinking.
 
G

Gina Whipp

Okay it knows sfrBoLDetail has no records and cboBillOfLadingID is null but
it still gives me the message which I want it to just close the form.


ManningFan said:
It's either being very naughty, or perhaps it is YOU who are not
listening to IT. I would put a break in the code and use the Immediate
window (or just mouse over the values) to see just what it thinks
cboBillOfLadingID and Form_sfrBoLDetail.Recordset.RecordCount are.
This usually gives critical insight into just what the form is
thinking.

Gina said:
Hello All,

I have this on the Form_Unload event. What I want if both conditions are
true then ask the question. But if one or both of these conditions are
true
then just close. I have tried the 3 condition below and none are
working.
Can someone help me as to why it won't listen to me?

Thanks,
Gina Whipp

TRIED: If Form_sfrBoLDetail.Recordset.RecordCount > 0 Or Not
IsNull([cboBillOfLadingID]) Then Exit Sub

TRIED: If Form_sfrBoLDetail.Recordset.RecordCount > 0 And Not
IsNull([cboBillOfLadingID]) Then Exit Sub

TRIED: If Form_sfrBoLDetail.Recordset.RecordCount > 0 And
Me.cboBillOfLadingID < 0 Then Exit Sub


----- Balance of code----

Dim Msg, Style, Title, Response, MyString

Msg = "There are no lifts on this Bill of Lading, it will be deleted!
Is that what you want to do?"
Style = vbYesNo + vbQuestion + vbDefaultButton1
Title = "Delete"

Response = MsgBox(Msg, Style, Title)

If Response = vbYes Then
MyString = "Yes"
DoCmd.SetWarnings False
DoCmd.RunSQL "DELETE tblBillOfLading.bolBillOfLadingID FROM
tblBillOfLading WHERE (((tblBillOfLading.bolBillOfLadingID) =
[Forms]![frmBillOfLading]![txtBillOfLadingID]));"
DoCmd.RunSQL "UPDATE tblGetBillOfLadingID SET
tblGetBillOfLadingID.gbolBillOfLadingNumber = [gbolBillOfLadingNumber]-1,
tblGetBillOfLadingID.gbolBillOfLadingID = Val([gbolBillOfLadingID])-1
WHERE
(((tblGetBillOfLadingID.gbolBillOfLadingID)=[Forms]![frmBillOfLading]![cboBillOfLadingID])
AND
((tblGetBillOfLadingID.gbolCustomerID)=[Forms]![frmBillOfLading]![cboCustomerID]));"
DoCmd.SetWarnings True
Else
MyString = "No"
DoCmd.CancelEvent
End If
 
G

Gina Whipp

Thank you ManningFan, I was NOT listening to IT :cool: But I am now, got it
fixed...


Gina Whipp said:
Okay it knows sfrBoLDetail has no records and cboBillOfLadingID is null
but it still gives me the message which I want it to just close the form.


ManningFan said:
It's either being very naughty, or perhaps it is YOU who are not
listening to IT. I would put a break in the code and use the Immediate
window (or just mouse over the values) to see just what it thinks
cboBillOfLadingID and Form_sfrBoLDetail.Recordset.RecordCount are.
This usually gives critical insight into just what the form is
thinking.

Gina said:
Hello All,

I have this on the Form_Unload event. What I want if both conditions
are
true then ask the question. But if one or both of these conditions are
true
then just close. I have tried the 3 condition below and none are
working.
Can someone help me as to why it won't listen to me?

Thanks,
Gina Whipp

TRIED: If Form_sfrBoLDetail.Recordset.RecordCount > 0 Or Not
IsNull([cboBillOfLadingID]) Then Exit Sub

TRIED: If Form_sfrBoLDetail.Recordset.RecordCount > 0 And Not
IsNull([cboBillOfLadingID]) Then Exit Sub

TRIED: If Form_sfrBoLDetail.Recordset.RecordCount > 0 And
Me.cboBillOfLadingID < 0 Then Exit Sub


----- Balance of code----

Dim Msg, Style, Title, Response, MyString

Msg = "There are no lifts on this Bill of Lading, it will be
deleted!
Is that what you want to do?"
Style = vbYesNo + vbQuestion + vbDefaultButton1
Title = "Delete"

Response = MsgBox(Msg, Style, Title)

If Response = vbYes Then
MyString = "Yes"
DoCmd.SetWarnings False
DoCmd.RunSQL "DELETE tblBillOfLading.bolBillOfLadingID FROM
tblBillOfLading WHERE (((tblBillOfLading.bolBillOfLadingID) =
[Forms]![frmBillOfLading]![txtBillOfLadingID]));"
DoCmd.RunSQL "UPDATE tblGetBillOfLadingID SET
tblGetBillOfLadingID.gbolBillOfLadingNumber =
[gbolBillOfLadingNumber]-1,
tblGetBillOfLadingID.gbolBillOfLadingID = Val([gbolBillOfLadingID])-1
WHERE
(((tblGetBillOfLadingID.gbolBillOfLadingID)=[Forms]![frmBillOfLading]![cboBillOfLadingID])
AND
((tblGetBillOfLadingID.gbolCustomerID)=[Forms]![frmBillOfLading]![cboCustomerID]));"
DoCmd.SetWarnings True
Else
MyString = "No"
DoCmd.CancelEvent
End If
 
G

Guest

I'm not the original poster here, however, for some reason I am not able to
post a new post so I'm hijacking this one. If anyone could help me I would
be greatly appreciative.

I have 2 questions:

1) I have an Access database that brings up a form automatically when the
program opens. However, it brings up this form to only fill 1/3 of the
monitor. How can I get this form to open full screen (maximized) upon
startup?

2) On a different form, I have a command button that used the wizard to
program "Add New Record". This button works fine, however, is there a way
(with a macro or such) to "on click" Add New Record and Select the Box that
will be the where the first data will be entered. Basically, I am trying to
make it where you can click the Add Record button and start typing in the
first field rather than click Add Record then click in the first field and
then start typing. Is this possible?

Thanks
 
J

Joan Wild

bnichols0330 said:
1) I have an Access database that brings up a form automatically when
the program opens. However, it brings up this form to only fill 1/3
of the monitor. How can I get this form to open full screen
(maximized) upon startup?

In the On Activate property choose [Event Procedure]; click on the build
button (...) and put
DoCmd.Maximize
2) On a different form, I have a command button that used the wizard
to program "Add New Record". This button works fine, however, is
there a way (with a macro or such) to "on click" Add New Record and
Select the Box that will be the where the first data will be entered.
Basically, I am trying to make it where you can click the Add Record
button and start typing in the first field rather than click Add
Record then click in the first field and then start typing. Is this
possible?

You can set the tab order of the form so that the first control is first in
the tab order - View, Tab Order in design view of the form.

Or you can add to the code behind the button:

Me.txtControlName.SetFocus

Substitute the name of the control for the first field for txtControlName
 
G

Guest

Joan, Thank you so much the help. That fixed both of my problems.

Thanks
Joan Wild said:
bnichols0330 said:
1) I have an Access database that brings up a form automatically when
the program opens. However, it brings up this form to only fill 1/3
of the monitor. How can I get this form to open full screen
(maximized) upon startup?

In the On Activate property choose [Event Procedure]; click on the build
button (...) and put
DoCmd.Maximize
2) On a different form, I have a command button that used the wizard
to program "Add New Record". This button works fine, however, is
there a way (with a macro or such) to "on click" Add New Record and
Select the Box that will be the where the first data will be entered.
Basically, I am trying to make it where you can click the Add Record
button and start typing in the first field rather than click Add
Record then click in the first field and then start typing. Is this
possible?

You can set the tab order of the form so that the first control is first in
the tab order - View, Tab Order in design view of the form.

Or you can add to the code behind the button:

Me.txtControlName.SetFocus

Substitute the name of the control for the first field for txtControlName
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top