Question : Feed query results from one form to another

Hi Experts,

I have a FORM1 bound to a table called DUAL with 2 TEXT fields named fakeURL and fakeOLPID.

The user needs to paste a URL into the field fakeURL and then select a command button that runs a query that does this:  

1.  SELECT MID(fakeURL,46,6) as fakeOLPID FROM DUAL

2.  then it needs to take that fakeOLPID and compare it with the field OLPID in a table called INVENTORY.  

IF fakeOLPID = OLPID, then it will open FORM_MAIN (which is bound to INVENTORY) filtered to the record.  

IF fakeOLPID does not = OLPID, then it will open FORM MAIN as a new record feeding fakeOLPID and fakeURL into INVENTORY as OLPID and URL, respectively.

So far, I have this:

INSERT INTO inventory (olpid, urlfield)
SELECT 'fakeolpid', 'fakeurl'
FROM dual
WHERE not exists (select * from inventory
where inventory.olpid = 'fakeolpid');

My problems are:

A) I don't know how to combine 1 and 2 into a single query
B) My append query works to filter an existing record but I don't know how to feed the 2 DUAL field values into the INVENTORY table if the record does not exist.

Note:  OLPID is the primary key in INVENTORY

Thanks!

Answer : Feed query results from one form to another

Hi,

this means that the string array "strOpenArgs" doesn't contain any item. You can see the reason if you enter "Debug.print Me.OpenArgs" in the Form Load event - because in the calling form you used "Me.fakeURL & "," & Me.FakeOLPID" (with a comma in between) and in the Form Load event you used "Split(Me.OpenArgs, "'")" (with a single quote as delimiter). You must use the same character in both cases, as I wrote above.
It's better not to use the single or double quote as character because it is used as SQL delimiter for strings. As "Split" can use not only single characters but even complete strings you could use

Me.fakeURL & "#-#" & Me.FakeOLPID
and
Split(Me.OpenArgs, "#-#")

instead or whatever you want and doesn't occur in your field values (and is no joker character like * or ?).

Cheers,

Christian
Random Solutions  
 
programming4us programming4us