Hello everyone. I have been working on this DB for quite some time and still can't figure out a way to do what I want to do. It's a database that keep track of drawings and engineering change etc. Aslo, the tables for drawings are grouped by year.
I have a Main Form and on that main form, several cmd buttons to initialize sub forms are located. There are a quite a few tables and the names are quite simple. For example, for drawing that are produced in 2008 are called "2008 Drawing" and so on.
So on the main form, when I click on "Search Drawing" button, it assumes that the user is searching for the drawing in the current year which is 2008. Therefore, it brings up the form I created for "2008 Drawing". On this form, there are a lot of data related to the drawing: Drawing Number, Title, Draft Person, Year, etc.
Also, there are two CMD buttons called "Exit" which exits the current form and go back to the Main Form and "Search" which queries the data.
What I want to be able to do is to prompt the user to enter the "Drawing Number" which is bound to "Drawing Number" column of the "2008 Drawing" table. When I press the "Search" button, I want it to get the "Drawing Number" that users entered and query the query I created base on table "2008 Drawing". When the query is done, I want to populate the data back in the form "2008 Drawing". There will be only one record because all the drawing numbers are unique.
This is what I did and did not work unfortunately.
------------------------------------------------
--------------------------------------------------
But the recSet.Open is giving me error.
All I want to be able to do is to be able to search one record at a time from the user input by pressing "Search" button. I also want to be able to switch between the forms by just choosing the "year drop down" list from the form. Say, if I choose "2007", it should close the form "2008 Drawing" and open up the "2007 Drawing" form and should automatically know to query the "2007 Drawing" table/query.
Any suggestion at all is really welcome.
Thanks.
I have a Main Form and on that main form, several cmd buttons to initialize sub forms are located. There are a quite a few tables and the names are quite simple. For example, for drawing that are produced in 2008 are called "2008 Drawing" and so on.
So on the main form, when I click on "Search Drawing" button, it assumes that the user is searching for the drawing in the current year which is 2008. Therefore, it brings up the form I created for "2008 Drawing". On this form, there are a lot of data related to the drawing: Drawing Number, Title, Draft Person, Year, etc.
Also, there are two CMD buttons called "Exit" which exits the current form and go back to the Main Form and "Search" which queries the data.
What I want to be able to do is to prompt the user to enter the "Drawing Number" which is bound to "Drawing Number" column of the "2008 Drawing" table. When I press the "Search" button, I want it to get the "Drawing Number" that users entered and query the query I created base on table "2008 Drawing". When the query is done, I want to populate the data back in the form "2008 Drawing". There will be only one record because all the drawing numbers are unique.
This is what I did and did not work unfortunately.
------------------------------------------------
Code:
Private Sub Form_Current()
' Move crusor to Drawing number
DrawingNumber.SetFocus
‘ Will it be like this to prompt user to enter drawing number?
Forms![2008 Drawing].[Drawing Number] = [Drawing Number:]
End Sub
----------------------------------------------
Public Sub cmdSearch_Click()
' SQL variable
Dim mySQL As String
' Select everything from 2008 Elec table and query the drawing number user provided
mySQL = "SELECT * FROM [2008 Drawing]"
DoCmd.RunSQL mySQL
End Sub
---------------------------------------------
But then, I realize that RunSQL can't run "SELECT" statement.
I need to get the "Drawing Number" from user before I press "Search" button. That's why I was thinking of prompting user to enter the "Drawing Number" in "Form_current".
Anyway, I changed code to the following because RunSQL can't do "SELECT":
-------------------------------------------------
Public Sub cmdSearch_Click()
' SQL variable
Dim mySQL As String
Dim con As Object
Dim recSet As Object
Set con = Application.CurrentProject.Connection
' Select everything from 2008 Elec table
mySQL = "SELECT * FROM [2008 Drawing]"
' Drawing Number is provided by user
Set recSet = CreateObject("ADODB.Recordset")
recSet.Open mySQL, con, adOpenStatic, adLockOptimistic, adCmdTable
End Sub
But the recSet.Open is giving me error.
All I want to be able to do is to be able to search one record at a time from the user input by pressing "Search" button. I also want to be able to switch between the forms by just choosing the "year drop down" list from the form. Say, if I choose "2007", it should close the form "2008 Drawing" and open up the "2007 Drawing" form and should automatically know to query the "2007 Drawing" table/query.
Any suggestion at all is really welcome.
Thanks.
Comment