Open FORM after INSERT INTO

radek225

Registered User.
Local time
Yesterday, 17:45
Joined
Apr 4, 2013
Messages
307
Is there any possibilities to open form after INSERT INTO? I think Ms Access can't fast refresh data in the table after that, so form opens up clean:/

Code:
...
strSQL = "INSERT INTO tblZlecenia (id_zlecenia_info, DataPrzyjecia) VALUES ('" & ostateczne & "', Date())"
CurrentDb.Execute strSQL, dbFailOnError
DoCmd.OpenForm "Formularz2", WhereCondition:="ID_Zlecenia=" & ostateczne
 
You need to concatenate the Date too..
Code:
strSQL = "INSERT INTO tblZlecenia (id_zlecenia_info, DataPrzyjecia) VALUES ('" & _
                                    ostateczne & "', [COLOR=Red][B]" & _[/B][/COLOR]
                                    [COLOR=Red][B]Format(Date, "\#mm\/dd\/yyyy\#") & "[/B][/COLOR])"
CurrentDb.Execute strSQL, dbFailOnError
DoCmd.OpenForm "Formularz2", WhereCondition:="ID_Zlecenia=" & ostateczne
 
No it's no the problem. The data in the table are correctly added. Problem is open form with id which was added a moment ago
 
Code:
    [COLOR=Red][B]Dim idRS As DAO.Recordset, ShowIdentity[/B][/COLOR]
    strSQL = "INSERT INTO tblZlecenia (id_zlecenia_info, DataPrzyjecia) VALUES ('" & _
                                        ostateczne & "', " & _
                                        Format(Date, "\#mm\/dd\/yyyy\#") & ")"
    CurrentDb.Execute strSQL, dbFailOnError
        
    [COLOR=Red][B]Set idRS = CurrentDB.OpenRecordset("SELECT @@IDENTITY AS LastID;")
    ShowIdentity = idRS!LastID
    idRS.Close[/B][/COLOR]
    
    DoCmd.OpenForm "Formularz2", WhereCondition:="ID_Zlecenia=" &[COLOR=Red][B] ShowIdentity[/B][/COLOR]
 
Maybe the form is designed with DataEntry = True??? If so it opens by default to a new record, and if that's the case, try . . .
Code:
DoCmd.OpenForm "YourForm", DataMode:=acFormEdit, WhereCondit . . .
. . . and force it back into edit mode.
 
Code:
    [COLOR=Red][B]Dim idRS As DAO.Recordset, ShowIdentity[/B][/COLOR]
    strSQL = "INSERT INTO tblZlecenia (id_zlecenia_info, DataPrzyjecia) VALUES ('" & _
                                        ostateczne & "', " & _
                                        Format(Date, "\#mm\/dd\/yyyy\#") & ")"
    CurrentDb.Execute strSQL, dbFailOnError
        
    [COLOR=Red][B]Set idRS = CurrentDB.OpenRecordset("SELECT @@IDENTITY AS LastID;")
    ShowIdentity = idRS!LastID
    idRS.Close[/B][/COLOR]
    
    DoCmd.OpenForm "Formularz2", WhereCondition:="ID_Zlecenia=" &[COLOR=Red][B] ShowIdentity[/B][/COLOR]

THX pr2-eugin, It works (in Form with one source), but I forgot that source of my FORM is not one table:/ I have a inner join "tblZlecenia" and "tblOffset" on tblZlecenia.id_zlecenia = tblOffset.id_zlecenia. Is there any possibilities to applay your concept to inner join? Should I add using INSERT INTO "id_zlecenia" to "tblOffset"?

Markk - DataEntry = False
 
Last edited:

Users who are viewing this thread

Back
Top Bottom