frosty90
I think I understand -- the operator enters a number, and you want to find the information using the reference number. The problem is that the information can be on any one of six tables.
I see ways to appraoch this.
First on the main form that accepts the reference number, for after update event for the reference number have a bit of code that does the following...
dim dbs as dao.database, rst as dao.recordset
dim strSQL1 as string, strSQL2 as string, strSQL as string
dim strRefNum as string
dim intTest as integer
dim strDoc as string
strSQL1 = "select * from "
strSQL2 = " where refNum = "
strRefNum = me.RefNum
set dbs = currentdb()
strSQL = strSQL1 & "tblMyTable1" & strSQL2 & strRefNum
set rst = dbs.openrecordset(strSQL1)
rst.movefirst
intTest = rst.recordcount
if intTest > 0 then
stdDoc frmMyForm1
end if
rst.close
strSQL = strSQL1 & "tblMyTable2" & strSQL2 & strRefNum
and repeat...
Then...
DoCmd.OpenForm stDoc, , , stRefNum
The nice thing is that if I understand your setup correctly, the operator only has to press one button and the logic should open the correct form.
Two problems with this -- repeat the code six times. Assume that the reference number will be found only in one table.
SECOND approach.
Create an index table...
tblRefNumIndx
RefNum (primary key)
RefTable (optional, indicates name of table info stored on)
RefForm (form to be used)
Then the logic for above is replaced with
an SQL statement to retrieve the name of the form.
...
strSQL = "select * from tblRefNumIndx where refnum = " & refnum
Grab from name
rst.movefirst
inttest = rst.recordcount
if inttest > 0 then
strDoc = rst!RefForm
DoCmd.OpenForm stDoc, , , stRefNum
else
msgbox "Error ...
end if
On the other end, you will need to create the logic to update tblRefNumIndx
(Sorry, I have to run so I am going to cut this short)
This solution is more efficient at the front end.
BUT, and this is a farily big BUT...
Your problem is that your database design is a little messed. I would have designed it a little differently where the reference number is only in one table.
Let me give you an example. I designed a database for tracking computer devices -- all sorts of devices -- servers, switches, PC's, printers, monitors, etc.
The problem was that each object, each device type had different properties. When I look at the specs for a PC and don't want to see monitor resolution or screen size. Likewise, when I look at a printer, I don't want to see number of fiber ports.
I went back to the drawing board several times on this one - every design came up with problems, similar to your issues. I finally came up with the following which I find works well...
tblMasterDevice
DevID
AssetTag
SerialNumber
DevGroup
- other info common to all devices
Then for each device group
tblServer
DevID
- specs needed for servers
tblPrinter
DevID
- specs needed for printers
etc
Then I would query the Master Device using the serial number or asset tag and voila, I would have my device information and the information for the device group.
Likewise, I can run queries to say find all PC's with less than 300 MHz CPU's -- works backwards and forwards.
This sound a bit similar to your needs. But I am not sure you are ready to go back to the drawing board.
Good luck on this one.
Richard