you define the global variable in a module, with the line
public gblInvNumber as long
this makes it persist throughout the application. You can use this same variable (or other variables) for other forms also, or define other variables If you re-use it, you need to be aware of that the value may have changed
in the module you also need a function, to be able to use the value in a query, as you cant directly read a variable in a query.
public function readGblInvNumber() as long
readGblInvNumber = nz(GblInvNumber,0)
end function
now you need to deifne a query (or you can do it with a sql statement). include the invoice table, and drag the invoice number into the design area. If you open the query, you will see every invoice number. If you now in the criteria section put
=readgblinvnumber() - the brackets have to be there
it will now only return any matches for the specific setting of the gblinvnumber - in this case the function returns 0, so you shouldnt get any.
NOW in your main form, after you enter the search number, when you click the search button, (you can refine it to do different things later), you need the buttons click event to include the following
gblinvnumber = nz(searchnumber ,0)
this sets the gblinvnumber to equal the value of the required number. the nz expression is defensive, as it deals with a problem that would happen if someone clicked the butoon while the searchnumber was blank.
now if you open the query we designed before you should see 1 record, if the searchnumber matches an invoicenumber and 0 records if not.
you can refer to this query in the code in a number of ways, but the dcount merely counts the items
hence we get, within the click event
gblinvnumber = nz(searchnumber ,0)
if dcount("*","my query name") = 0 then
msgbox("no matches found")
----- any other code -----
else
msgbox("matches found")
------ any other code -----
end if
Now you know (whether) what you want to do with your subform etc, However, If all this is new to you, you will really struggle to get very far designing a usable database, as this is fairly basic stuff. Pretty well the whole of access is based on managing events and coding actions based on those events.