Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
182 views
in Technique[技术] by (71.8m points)

vba - Disappearing Form

I'm working on an access form that contains a combo box and other controls. When I click on button, it calls a subroutine that builds a table that populates the combo box. Works great, but the form goes away. When I open it up, the box looks good, but The form HAS to stay visible. Is there a setting that I need to set to keep this from happen. Please advise.

 Private Sub Command18_Click()
        Load_Contract_Table
 End Sub


 Public Sub Load_Contract_Table()

   Dim daDb As DAO.Database
   Dim rst1 As Recordset
   Dim rst2 As Recordset

   Dim selContract As String

   Set daDb = CurrentDb
   Set rst1 = daDb.OpenRecordset("tblContracts")
   Set rst2 = daDb.OpenRecordset("tblContractList")

   Dim svContract As String
   Dim svID As Integer
   Dim newCont As String
   Set daDb = CurrentDb

    svContract = " "

    st1.MoveFirst

   Do Until rst1.EOF
     If rst1!Contract <> svContract Then
       MsgBox "Contract= " & rst1!Contract
       svContract = rst1!Contract
       svID = rst1!ID
       newCont = rst1!Contract
  
       AddCon newCont, svID
     End If

     rst1.MoveNext
  Loop

 End Sub


 Public Sub AddCon(newCont, svID)
  Dim daDb As DAO.Database
  Dim rst1 As Recordset
  Dim rst2 As Recordset

 Dim selContract As String


Set daDb = CurrentDb
Set rst1 = daDb.OpenRecordset("tblContracts")
Set rst2 = daDb.OpenRecordset("tblContractList")

 rst2.AddNew
 rst2!Contract = newCont
 rst2!ID = svID
 rst2.Update
 rst2.Close

  Set rst2 = Nothing
   DoCmd.Close
End Sub
question from:https://stackoverflow.com/questions/65925333/disappearing-form

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

I put DoCmd.OpenForm at the end of a subroutine and the problem went away.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...