Full Version: returning a checkbox if a query is null.
UtterAccess Forums > Microsoft® Access > Access Forms
chrisfullwood
im running a form which has a group of subforms, each of which (if there are no errors) show nothing. im trying to make the form open a msg box that lists the errors that are found on the form.
im having trouble making it work if the querys have nothing in them, ive been working with.
If ([ERRORduppktnumbers subform].Form![NumberOfDups]) = Null Then
strmessage = strmessage & "There Are Duplicate Packet Numbers" & vbCrLf
Else
Exit Sub
End If
If Len(strmessage) > 0 Then
MsgBox strmessage
Exit Sub
End If
it tells me that there is no value.. which is the point.. i just want it to continue if there is no value.
ive also tried using if isnull [ERRORduppktnumbers subform] and it didnt do anything either.
any ideas would be great thanks.
MattJ
Want what to continue? What should it continue to do? If this is only a part of your code, and you have similar code that checks the other sub-forms, then you need to remove the Exit Sub command.
chrisfullwood
ok firstly im retarded... i meant messagebox, not a checkbox.. and i just now notice this.
what im trying to do, is if there is an error (which will be indicated by there being a result in a set of queries) then to show a msgbox which lists which errors there are) if there are no errors, then it just loads the form as normal, or a messagebox to show there are no errors would be fine too.
MattJ
To check if there are any results in the queries, I suggest you use a DCOUNT funtion on the form's On Load event:
If DCount("*", YourQueryName) > 0 Then
MsgBox "there are errors"
End If
If Dcount("*", Your SecondQuery)> 0 Then
MsgBox
EndIf
Etc.....
chrisfullwood
thanks ill give that a try.
please forgive my moments of retardation earlier.
its been a long day alread.
Thanks again
Chris.
forgot to send this, before i tried it, but it gives me a domain aggregate error. as the query doesnt actually return a value if there are no errors.
MattJ
I'm sorry, I don't understand what you mean by "I forgot to send this before I tried it, but it give me a error".
What gives you a error? The dcount function?
chrisfullwood
what i meant was, i was typing the reply, forgot to send it.... and while i had it open i entered and tested the code you suggested, and while running the code i got an error.
ve messed with it and got this far...
Dim errorcheck As Integer
errorcheck = DCount("[ERRORduppktnumbers subform].Form![NumberOfDups]", "ERRORduppktnumbers")

If errorcheck = True Then
strmessage = strmessage & "There Are Duplicate Packet Numbers" & vbCrLf
the problem im running into is that the query doesnt return a value... it either has something in it, or it is empty.. so its just not doing anything... ive tried > 0 and it says there are dup numbers regardless of whether there is or not.
MattJ
Have you looked at the structure of the DCount function (check the Access help files)? I'm surprised that's the only error you received.

The DCount function returns the number of records in a specifiec recordset (table, query, or SQL SELECT statement).

So Dcount ("*", YourQuery) would count all records returned by a query named "YourQuery". If you replace this query name with the query name or SQL statements that your form is bound to, it will count to see if there are any records. There is no need to reference your form.
Secondly, you have dimensioned (or declared) the variable errorcheck as an integer. This is correct.
However, the next line in your code tests to see if errorcheck equals True, which it never will. True is a boolean value.

So, try something like (make sure to place the name of your query in the function):

Dim errorcheck As Integer
errorcheck = DCount("*", "Your Query name that your form is bound to")

If errorcheck > 0 Then
strmessage = "There Are Duplicate Packet Numbers" & vbCrLf
chrisfullwood
yeah the true bit, i was just messing with it, i originally had it as > 0 but it still didnt work...
so a friend suggest try true.
ill give it another shot in the format you have and see how it works.
thanks
chrisfullwood
ok i finally got it to work, thanks for all your help sad.gif
but heres the best bit, it doesnt work with
strmessage = strmessage & "There Are Duplicate Packet Numbers" & vbCrLf
so that i cut put multiple results together...
it only works with straight
msgbox "there are duplicate packets"
interesting huh?


Edited by: chrisfullwood on Thu Aug 16 16:08:38 EDT 2007.
MattJ
Post all of the code.
This is a "lo-fi" version of UA. To view the full version with more information, formatting and images, please click here.