|
-
Jun 19th, 2006, 10:08 AM
#1
Thread Starter
Member
Message Box if there are No Records in a Form
Hi
I am trying to get a Message Box if there are No Records in a Form, here is the code.
thank you in advance
Pretty
VB Code:
Private Sub Command40_Click()
On Error GoTo Err_Command40_Click
Dim stDocName As String
Dim stLinkCriteria As String
Dim intHolder As Integer
intHolder = DCount("UnitAreaName", "qryMainDue")
If intHolder > 0 Then
stDocName = "frmDue"
DoCmd.OpenForm stDocName, , , stLinkCriteria
Else
MsgBox "There are no records!"
End If
Exit_Command40_Click:
Exit Sub
Err_Command40_Click:
MsgBox Err.Description
Resume Exit_Command40_Click
End Sub
-
Jun 19th, 2006, 10:10 AM
#2
Re: Message Box if there are No Records in a Form
You are using Access VBA?You could write code in the Forms Load event and check for records in there.
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Jun 19th, 2006, 10:15 AM
#3
Re: Message Box if there are No Records in a Form
?? when I try similar code.. it works fine
VB Code:
Dim intHolder As Integer
intHolder = DCount("ID", "Query1")
If intHolder > 0 Then
DoCmd.OpenForm "Form1"
Else
MsgBox "No Records"
End If
JPnyc rocks!! (Just ask him!)
If u have your answer please go to the thread tools and click "Mark Thread Resolved"
-
Jun 19th, 2006, 10:19 AM
#4
Thread Starter
Member
Re: Message Box if there are No Records in a Form
Yes i am using Access VBA.. I tried in FORM LOAD event but I am getting error msg saying "You entered an invalid argument in a domain aggregate function".
Thanks
Pretty
-
Jun 19th, 2006, 10:23 AM
#5
Re: Message Box if there are No Records in a Form
Well you can open the forms recordset initially like static posted and check the records and then only open the form itf records exist.
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Jun 19th, 2006, 10:27 AM
#6
Re: Message Box if there are No Records in a Form
well thats what she is doing...
my guess is though.. the Dcount is returning > 0 thats why its opening the form..
check to make sure your looking at the SAME data as the form is... and check to see if its really empty
JPnyc rocks!! (Just ask him!)
If u have your answer please go to the thread tools and click "Mark Thread Resolved"
-
Jun 19th, 2006, 10:31 AM
#7
Re: Message Box if there are No Records in a Form
Well I think the error is more related to the passing of a nullstring as the criteria and giving different recordset results. stLinkCriteria is never populated.
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Jun 19th, 2006, 10:50 AM
#8
Thread Starter
Member
Re: Message Box if there are No Records in a Form
No I have no records in RecordSource (qryMainDue) ... still form is opening... i am confused here :-)
By the way i just started working with VB Access, i am not an expert
Static i tried ur code as well,, didnt work 
I have my Main switchboard named frmMainMenu and there i have my button "frmDue" (my Sub Form)...
-
Jun 19th, 2006, 10:53 AM
#9
Re: Message Box if there are No Records in a Form
Can you describe the design of your form as I see now that there is a sub form involved. What recordset is tied to what form?
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Jun 19th, 2006, 11:00 AM
#10
Thread Starter
Member
Re: Message Box if there are No Records in a Form
Main Form Called frmMainMenu (just switchboard) I have several buttons thats it, no record set.. one of the buttons called command40(no name:-). When user click on that i need my sub form (frmDue) to be open. but i need a Message Box if there are No Records in a Form.
frmDue from recordsource qryMainDue.
thanks for your time
-
Jun 19th, 2006, 11:01 AM
#11
Re: Message Box if there are No Records in a Form
alos.. put a breakpoint on this line:
to add the breakpoint click in the gray column next to the line... it should add a dot in the column and highlight the line...
now go back to the form and trigger the code.. (click the button)
it should stop on the breakpoint...
put your mouse over intHolder and it should give u a tooltip with the value of it...
whats the value?
JPnyc rocks!! (Just ask him!)
If u have your answer please go to the thread tools and click "Mark Thread Resolved"
-
Jun 19th, 2006, 11:10 AM
#12
Re: Message Box if there are No Records in a Form
It should be qryMainDue then and is this an actual nested subform or just a secondary form?
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Jun 19th, 2006, 11:19 AM
#13
Thread Starter
Member
Re: Message Box if there are No Records in a Form
i am getting a error msg saying "u cancelled the previous operation" :S i added the breakpoint its not even start trigger the code..
-
Jun 19th, 2006, 11:20 AM
#14
Thread Starter
Member
Re: Message Box if there are No Records in a Form
-
Jun 19th, 2006, 11:32 AM
#15
Re: Message Box if there are No Records in a Form
Can you zip and attach your db in a post?
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Jun 19th, 2006, 11:33 AM
#16
Thread Starter
Member
Re: Message Box if there are No Records in a Form
its a separate form(frmDue) .. main swichboard doesnt have any forms only buttons
-
Jun 19th, 2006, 11:34 AM
#17
Thread Starter
Member
Re: Message Box if there are No Records in a Form
nooo i have 1000 records ... its confidencial
-
Jun 19th, 2006, 11:39 AM
#18
Re: Message Box if there are No Records in a Form
how about removing all the records and confidential data?
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Jun 19th, 2006, 11:45 AM
#19
Thread Starter
Member
Re: Message Box if there are No Records in a Form
still i have other coding for my other sub forms.... all i did using VB coding... i work for a bank i cant do that u know...
-
Jun 19th, 2006, 11:47 AM
#20
Thread Starter
Member
Re: Message Box if there are No Records in a Form
its ok i will find an other way to fix the problem... i am going to have empty form for now until i fix....
-
Jun 19th, 2006, 12:09 PM
#21
Re: Message Box if there are No Records in a Form
Ok, its just hard to debug Access forms without seeing them.
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Jun 19th, 2006, 12:47 PM
#22
Thread Starter
Member
Re: Message Box if there are No Records in a Form
hmm ok thanks
-
Jun 19th, 2006, 12:51 PM
#23
Re: Message Box if there are No Records in a Form
Citi? 
anyways.. u added the breakpoint and now it wont even work? u mustve changed something....
When u open "qryMainDue" (from the database window) does it return results?
is it using any params from open forms etc?
JPnyc rocks!! (Just ask him!)
If u have your answer please go to the thread tools and click "Mark Thread Resolved"
-
Jun 19th, 2006, 12:58 PM
#24
Thread Starter
Member
Re: Message Box if there are No Records in a Form
no ididnt change anything i have same code as i have above.. if i just open qryMainDue i have no problem.. qryMainDue has criteria ..first it asks year from them user then the month.. then it gives them issues due on that specific month of the year...
-
Jun 19th, 2006, 01:11 PM
#25
Re: Message Box if there are No Records in a Form
so when u do the Dcount() does it ask for the criteria?
Where is it getting the criteria from when u open the form?
is the form bound to that query??
as was said before.. hard to pinpoint without a db to play with.
I used to work for Citigroup so I know allll about need for confidentiality...
copy the database.. open up the copy and clear the tables of all confidential data.
then zip and attach it or if u want.. PM it to me, that way it will not be "public"
JPnyc rocks!! (Just ask him!)
If u have your answer please go to the thread tools and click "Mark Thread Resolved"
-
Jun 19th, 2006, 01:29 PM
#26
Thread Starter
Member
Re: Message Box if there are No Records in a Form
Did i say i work for Citi? i just said bank...
DCount("UnitAreaName", "qryMainDue")... frmDue bounds to qry (qryMainDue).when i click the button on the Main switchboard, the form is not getting the qry "qryMainDue" (recordsource).. thats why its saying "You cancelled the previous operation" it doesnt read the qry criteria i think...just confused
-
Jun 19th, 2006, 01:35 PM
#27
Thread Starter
Member
Re: Message Box if there are No Records in a Form
if there is no criteria then the form working fine....
-
Jun 19th, 2006, 01:46 PM
#28
Re: Message Box if there are No Records in a Form
put a textbox in the main form.. have the user enter the criteria in the textbox then in the query criteria section
=[Forms].[Form2].[Text1]
something like that.. so it reads the criteria from the switchboard
another method...
create a public funtion in a module
VB Code:
Public Function GetCrit() As String
GetCrit = 5
End Function
something along those lines... that can read public variables that u have set from the button click
then just put this in the criteria field
GetCrit()
JPnyc rocks!! (Just ask him!)
If u have your answer please go to the thread tools and click "Mark Thread Resolved"
-
Jun 19th, 2006, 02:20 PM
#29
Thread Starter
Member
Re: Message Box if there are No Records in a Form
i knew the first method, but i didnt wnat to have txtbox in my swichboard.. i am going to try doing 2nd method u mentioned.. thank you
Pretty
-
Jun 19th, 2006, 02:29 PM
#30
Re: Message Box if there are No Records in a Form
Just to explain it better:
in a module put this:
VB Code:
Public sCrit1 As String
Public sCrit2 As String
Public sCrit3 As String
Public Function GetCrit1() As String
GetCrit = sCrit1
End Function
Public Function GetCrit2() As String
GetCrit = sCrit2
End Function
Public Function GetCrit3() As String
GetCrit = sCrit3
End Function
THen in your form set the variables before its called...
VB Code:
Private Sub Command40_Click()
[B] sCrit1 = "a"
sCrit2 = "b"
sCrit3 = "c"[/B]
On Error GoTo Err_Command40_Click
Dim stDocName As String
Dim stLinkCriteria As String
Dim intHolder As Integer
intHolder = DCount("UnitAreaName", "qryMainDue")
If intHolder > 0 Then
stDocName = "frmDue"
DoCmd.OpenForm stDocName, , , stLinkCriteria
Else
MsgBox "There are no records!"
End If
Exit_Command40_Click:
Exit Sub
Err_Command40_Click:
MsgBox Err.Description
Resume Exit_Command40_Click
End Sub
then u can use
GetCrit1()
GetCrit2()
GetCrit3()
in the criteria fields
JPnyc rocks!! (Just ask him!)
If u have your answer please go to the thread tools and click "Mark Thread Resolved"
-
Jun 19th, 2006, 02:49 PM
#31
Thread Starter
Member
Re: Message Box if there are No Records in a Form
How do i get the user input ...
VB Code:
InputBox("Please enter year")
-
Jun 19th, 2006, 02:54 PM
#32
Re: Message Box if there are No Records in a Form
sCrit1 = Inputbox("Please Enter Year")
JPnyc rocks!! (Just ask him!)
If u have your answer please go to the thread tools and click "Mark Thread Resolved"
-
Jun 19th, 2006, 03:01 PM
#33
Thread Starter
Member
Re: Message Box if there are No Records in a Form
error msg i am getting now "undefined function GetCrit1 in Expression" 
its time to leave now so i am going to try it tmr..
many thanks ....
your help is appreciated.
-
Jun 19th, 2006, 03:14 PM
#34
Re: Message Box if there are No Records in a Form
u put the functions in a module? (Made them public?)
just like this? (PS.. I just noticed that I was not setting the function to the value so use this code in the module now)
VB Code:
Public sCrit1 As String
Public sCrit2 As String
Public sCrit3 As String
Public Function GetCrit1() As String
GetCrit1 = sCrit1
End Function
Public Function GetCrit2() As String
GetCrit2 = sCrit2
End Function
Public Function GetCrit3() As String
GetCrit3 = sCrit3
End Function
JPnyc rocks!! (Just ask him!)
If u have your answer please go to the thread tools and click "Mark Thread Resolved"
-
Jun 20th, 2006, 08:14 AM
#35
Thread Starter
Member
Re: Message Box if there are No Records in a Form
hmm thank you so much ... i am done :P Thanks a bunch Static and Robdog............
-
Jun 20th, 2006, 09:53 AM
#36
Re: Message Box if there are No Records in a Form
Cool. glad it works now... just a tidbit.. another way to do this that would reduce code:
VB Code:
Public sCrit(9) As String
Public Function GetCrit(cNum As Integer) As String
GetCrit = sCrit(cNum)
End Function
then u could set them line
sCrit(0) = "Whatever"
sCrit(1) = "This"
then in the Query Criteria
GetCrit(0)
etc....
also, if this thread is resolved now, please click thread tools > mark thread resolved so we all know its been answered Thanks!!!
JPnyc rocks!! (Just ask him!)
If u have your answer please go to the thread tools and click "Mark Thread Resolved"
-
Jun 20th, 2006, 10:06 AM
#37
Thread Starter
Member
Re: Message Box if there are No Records in a Form
opps..one more question...
when i have no records, the form working fine, i am getting the msg "there is not records", but when there are records (>0) then i am getting prompt 2 times, it asking year then month, again year and month?
VB Code:
Dim intHolder As Integer
[B] intHolder = DCount("UnitAreaName", "qryMainDue")
If intHolder > 0 Then
stDocName = "frmDue"
DoCmd.OpenForm stDocName, , , stLinkCriteria[/B]
Else
MsgBox "There are no records!"
End If
i couldnt figure it out
-
Jun 20th, 2006, 10:14 AM
#38
Re: Message Box if there are No Records in a Form
what are u using this for? stLinkCriteria
try just this:
DoCmd.OpenForm stDocName
JPnyc rocks!! (Just ask him!)
If u have your answer please go to the thread tools and click "Mark Thread Resolved"
-
Jun 20th, 2006, 10:22 AM
#39
Thread Starter
Member
Re: Message Box if there are No Records in a Form
no i am not using it (stlinkcriteria)
???:S
-
Jun 20th, 2006, 10:22 AM
#40
Thread Starter
Member
Re: Message Box if there are No Records in a Form
VB Code:
Private Sub Command40_Click()
sCrit1 = "a"
sCrit2 = "b"
Dim stDocName As String
stDocName = "frmDue"
Dim intHolder As Integer
intHolder = DCount("UnitAreaName", "qryMainDue")
If intHolder > 0 Then
DoCmd.OpenForm stDocName
Else
MsgBox "There are no records!"
End If
End Sub
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|