Link to home
Create AccountLog in
Avatar of perennial
perennial

asked on

Refresh

I have the following code. After the sql run, I need to REFRESH the database so that the following code could see the table.

I try putting me.refresh  and justh refresh...it give me compile error.

Any ideas???

Function AlterTableSortId()
''Add sortId field to tblData

    Dim dbs As Database
    Dim myDate As String

       

Set dbs = OpenDatabase("Production Planning.mdb")
   
myDate = (InputBox("Enter Sticking Date", "Enter Date"))

    CurrentDb.Execute " SELECT tblStkDat.ISNo, tblStkDat.ItemNo, tblStkDat.Size, " _
    & " tblUniqueItemNoPlantName.FirstOfPlantName, tblStkDat.DayStick, " _
    & " tblStkDat.FltStick, tblBench.Bench, tblBench.BQty, tblStkDat.DatSowd, " _
    & " tblUniqueItemNoPlantName.Genus, IIf([Genus]=""THYMUS"",(([Size]*[Bqty])*2),([Size]*[Bqty])) AS TotalCut, " _
    & " CStr(Int(([TotalCut]*4/60/60/2)))+"":""+Right(""00"" & CStr(Int((([TotalCut]*4/60/60/2)-Int(([TotalCut]*4/60/60/2)))*60+0.5)),2) AS TotalTime " _
    & " INTO tblData " _
    & " FROM tblUniqueItemNoPlantName INNER JOIN (tblStkDat INNER JOIN tblBench ON " _
    & " (tblStkDat.ISNo = tblBench.ItemNum) AND (tblStkDat.DayStick = tblBench.DayStick)) " _
    & " ON tblUniqueItemNoPlantName.ItemNo = tblStkDat.ItemNo " _
    & " WHERE (((tblStkDat.DayStick)= #" & CDate([myDate]) & "# )); "
   
'''Refresh  >>>>>>Need refresh here.

    dbs.Execute "ALTER TABLE tblData " _
        & "ADD COLUMN SortId Long Integer;"
       
    dbs.Close
   
End Function

Thanks

perennial
SOLUTION
Avatar of stevbe
stevbe

Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
See answer
Avatar of perennial
perennial

ASKER

Still giving me run-time error:

Cannot find table or constraint.

It not seeing the newly create table.

I have to hit F5 after the module run to see the table... is there a way to do that?

perennial
OK - you are executing the query using CurrentDb, but your target database is dbs. Try replacing the first execute line with:

    dbs.Execute " SELECT tblStkDat.ISNo, tblStkDat.ItemNo, tblStkDat.Size, " _
    & " tblUniqueItemNoPlantName.FirstOfPlantName, tblStkDat.DayStick, " _
    & " tblStkDat.FltStick, tblBench.Bench, tblBench.BQty, tblStkDat.DatSowd, " _
    & " tblUniqueItemNoPlantName.Genus, IIf([Genus]=""THYMUS"",(([Size]*[Bqty])*2),([Size]*[Bqty])) AS TotalCut, " _
    & " CStr(Int(([TotalCut]*4/60/60/2)))+"":""+Right(""00"" & CStr(Int((([TotalCut]*4/60/60/2)-Int(([TotalCut]*4/60/60/2)))*60+0.5)),2) AS TotalTime " _
    & " INTO tblData " _
    & " FROM tblUniqueItemNoPlantName INNER JOIN (tblStkDat INNER JOIN tblBench ON " _
    & " (tblStkDat.ISNo = tblBench.ItemNum) AND (tblStkDat.DayStick = tblBench.DayStick)) " _
    & " ON tblUniqueItemNoPlantName.ItemNo = tblStkDat.ItemNo " _
    & " WHERE (((tblStkDat.DayStick)= #" & CDate([myDate]) & "# )); "
I meant to say - you are executing the *first* query using CurrentDb.
shanesuebsahakarn,

OK, this seem to work but where did it put my table?  When I go to the table it's not showing, I try to run the module again...it say that the table alreay exist.

perennial
ASKER CERTIFIED SOLUTION
Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
Thanks, that did it.

perennial