Hello I just want to know on how to make a continuously questionnaire form in access that will update all the table once all the question have been filled. but before it reached end of the page, the user will be able to edited back and forth from forms to forms.
so it will be like this:
Total 30 forms
One form only update 1-3 fields in the table
Once the user finished with one form, the form will close and open another form.
The user will be able to back to previous form and edit it.
The buttons that it available only 2 buttons back arrow and next arrow(save data and move to another form and close current form)
The last form will save all the data.
When user finished all the question, the form will allows to be reopened from the first one and it will insert entirely new line of user data in table.
The one that i have done is
I create a form, with a box and tag, connected directly to the table, so it will updated in real time. so user can back and forth to edit it
"Next" button, using macro to close and open new form.
Final form using the folowing VB code to update the table:
Private Sub Close_Click()
CurrentDb.Execute "INSERT INTO Demographics(vid, cid, dobd, gend, heght, heght2, wgt, wgt2, lschool, secschl, qualify, hqlify, army, abranch )" & _
"VALUES('" & vid1 & "','" & cid1 & "','" & dobd1 & "','" & gend1 & "','" & heght1 & "','" & heght21 & "','" & wgt1 & "','" & wgt21 & "','" & lschool & "','" & secschl1 & "','" & qualify1 & "','" & hqilfy1 & "','" & army1 & "','" & abranch1 & "')"
cmdClear_Click
cmdClose_Click
End Sub
Private Sub cmdClose_Click()
DoCmd.Close
End Sub
Private Sub cmdClear_Click()
vid1 = ""
cid1 = ""
dobd1 = ""
gend1 = ""
heght1 = ""
heght21 = ""
wgt1 = ""
wgt21 = ""
lschool1 = ""
secschl = ""
qualify = ""
hqlify = ""
army = ""
abranch = ""
End Sub
Private Sub Form_Current()
End Sub
Problem:
Final page script above wouldnt insert the data into the table at all.
It can insert data into table, if i indexed the column in the table, but it will end up messy if i did a lot of updates
My Questions:
Can anyone suggest me the correct VB script to do this continuously form activity, instead of update entire table per-form.
How do I create a form like in access 2003 on which i can create switchboard with login for user only, and special login access to the database only for administrator, so it will like an application. (im using Access 2010 .accdb file)
sorry for the long post, just want to make sure everything is clear, any answer would be greatly appreciated.
Thank you in advance
Regarding your first question:
This is one of those cases where a bound form could prove to be handy.
You can use INSERT INTO, but you'd need to generate a different query for each form in order to avoid errors. If you set all of your forms to bind to the same table, though, the form fields can interact directly with the table without requiring a lot of code.
Try the following example, using 3 forms (though you can easily extend this out to 30 forms).
Each form has:
A hidden field, ctlID (bound to the table's ID field)
Any number of other fields, bound to matching fields in the table
A 'Next' button, cmdNext (or in the case of the last form, cmdFinish)
You can use the WhereCondition argument of DoCmd.OpenForm to keep referring to the same record across multiple forms.
Here's the code:
' Form1 code:
Private Sub Form_Load()
DoCmd.GoToRecord , , acNewRec
End Sub
Private Sub cmdNext_Click()
Dim iID As Long
iID = Me.ctlID.Value
DoCmd.Close acForm, Me.Name
DoCmd.OpenForm "Form2", , , "ID = " & iID
End Sub
' Form2 code:
Private Sub cmdNext_Click()
Dim iID As Long
iID = Me.ctlID.Value
DoCmd.Close acForm, Me.Name
DoCmd.OpenForm "Form3", , , "ID = " & iID
End Sub
' Form3 code:
Private Sub cmdFinish_Click()
DoCmd.Close acForm, Me.Name
End Sub
Related
I'm having issues with my Microsoft Access project.
The project comprises of two forms called, InfoForm and SearchBox.
InfoForm form
The InfoForm form is the primary-form, and has the following:
Custom navigation buttons, which are; Next and Prev
A custom Search button, which opens up the SearchBox form.
SearchBox form
The SearchBox form is used to browse and open individual records, and has the following:
List of available individual records
Open button
Individual records
The individual records open into the InfoForm form.
I use this code on the Open' button of theSearchBox` form, as follows:
Private Sub Command1_Click()
Dim strLN As String
strLN = Me.SearchResults.Column(0)
Dim strGN As String
strGN = Me.SearchResults.Column(1)
Dim strMN As String
strMN = Me.SearchResults.Column(2)
DoCmd.OpenForm "InfoForm", acNormal, , _
"[Last Name] = '" & strLN & "' And " & _
"[Given Name] = '" & strGN & "' And " & _
"[Middle Name] = '" & strMN & "'"
DoCmd.Close acForm, "SearchBox"
End Sub
This code works perfectly when the InfoForm form is first opened, right up until an individual record is opened.
At this point, the navigation buttons "Next" and "Prev" on the 'InfoForm' form stop working.
Please help. Thank you.
As #Andre noted, if the form is filtered to a single record then there are no succeeding or previous records to navigate to. Does your filter criteria result in a single record dataset?
An alternative is to open the form unfiltered (or with a filter that returns a restricted dataset but will usually still have multiple records) and 'go to' the desired record, then there will be succeeding and preceding records to navigate. Example from my code:
To open form:
DoCmd.OpenForm "Samples", , , , , acDialog, strLabNum
Then code behind the opened form:
Private Sub Form_Open(Cancel As Integer)
Me.RecordsetClone.FindFirst "LabNum='" & Me.OpenArgs & "'"
Me.Bookmark = Me.RecordsetClone.Bookmark
End Sub
I have create two forms, named Main and Individual. Main has one table named frmFID, and a combobox named frmEth. I want to send the frmID value to another textbox which is present in another form.
Private Sub cmdLog_Click()
Dim abc As String
Dim xyz As String
abc = "Insert into Main(FID, Ethnicity) Values('" & Me.frmFID & "', '" & Me.frmEth & "')"
CurrentDb.Execute (abc)
xyz="Insert into Individual(FID) Values(' "& Me.frmFID & "')"
CurrentDb.Execute(xyz)
DoCmd.Close
DoCmd.OpenForm "Individual"
End Sub
Your code is pretty much unreadable the way it is formatted. In any case you can send data to a form that you are opening by using the OpenArgs parameter of DoCmd.OpenForm. If the form is already open you can access it from anywhere like this:
Forms([FormName]).[TextBoxName]="Value to Push"
I am creating a user interface based off of one internal and two linked (external) Access datasheets in Access 2013.
Two of the fields on my UI are combo boxes that read from the linked datasheets and display the options. This is so that the entries for suppliers and material types are called-out consistently and typos are avoided. However, I would like to add the following functionality:
-If a new value is entered into the combo box the user will be prompted to fill out the necessary information on the new value. This information will subsequently be saved to the appropriate linked datasheet.
How would I go about setting up the prompt from the combo boxes themselves? It would require Access to open a form or sub-form that will, in turn, save to the linked datasheet.
I'd prefer it to be automatic, instead of end-user prompted so that it isn't skipped. It's been years since I played around with VB, so I would like to avoid that if possible and use Access' built-in functions (even if it requires a little more time). Thank you in advance!
Alright, so I was able to do it after researching the "OnNotInList" function and a little VB code.
In the OnNotInList section of the 'Event' properties sheet, I chose 'Code Builder' and entered the following:
Private Sub Supplier_NotInList(NewData As String, Response As Integer)
Dim ctl As Control
Dim dbsCustomerDatabase As Database
On Error GoTo Supplier_NotInList_Err
Dim intAnswer As Integer
Dim strSQL As String
intAnswer = MsgBox("The supplier " & Chr(34) & NewData & _
Chr(34) & " is not currently listed." & vbCrLf & _
"Would you like to add it to the list now?" _
, vbQuestion + vbYesNo, "Spire Manufacturing Solutions")
' Adding the new entry to the list:
If intAnswer = vbYes Then
strSQL = "INSERT INTO CustomerList([CustomerName]) " & _
"VALUES ('" & NewData & "');"
DoCmd.SetWarnings False
DoCmd.RunSQL strSQL
DoCmd.SetWarnings True
MsgBox "The new supplier has been added to the list." _
, vbInformation, "Spire Manufacturing Solutions"
Response = acDataErrAdded
' Opening the Supplier datasheet to add details
' to the new entry:
MsgBox "Opening Supplier database for new entry..."
DoCmd.OpenTable "CustomerList", acViewNormal, acEdit
End If
Supplier_NotInList_Exit:
Exit Sub
Supplier_NotInList_Err:
MsgBox Err.Description, vbCritical, "Error"
Resume Supplier_NotInList_Exit
End Sub
This allowed me to automatically prompt the user to add the details for a new supplier if they enter a new supplier name. Or, cancel the entry if they simply misspelled it. I'd quite forgotten how versatile VB was. Thank you all for your assistance in getting me headed in the right direction!
I am trying to create a form with 3 combo boxes on which will run a report from existing data. The combo boxes will filter down based on the data chosen in the next level up combo box.
However I'm having issues with the Batch Number Combobox not populating it's list
Now this is my VBA script:
Private Sub Form_Load()
Me.cboDate.RowSource = ""
Me.cboBatchNo.RowSource = ""
End Sub
Private Sub cboBottleNo_AfterUpdate()
Dim sDateSource As String
sDateSource = "SELECT [tblNewCC].[Date] FROM [tblNewCC]" & _
" WHERE [tblNewCC].[BottleNo] = " & Me.cboBottleNo.Value
Me.cboDate.RowSource = sDateSource
Me.cboDate.Requery
End Sub
Private Sub cboDate_AfterUpdate()
Dim sBatchSource As String
sBatchSource = "SELECT [tblBatchTotals].[BatchNo] FROM [tblBatchTotals] INNER JOIN [tblNewCC] ON [tblBatchTotals].[RunNo]=[tblNewCC].[RunNo]" & _
" WHERE [tblNewCC].[BottleNo] = " & Me.cboBottleNo.Value & _
" AND [tblNewCC].[Date] = " & Me.cboDate.Value
Me.cboBatchNo.RowSource = sBatchSource
Me.cboBatchNo.Requery
End Sub
From what I can see this is working alright on the vba side as I can see it replacing the rowsource of the batch number combobox, and in datasheet view it is giving me results.
However the combobox isn't showing anything in it's list....
Unless I go in make a change and save the sql query again.
Any clues?
The last part of sBatchSource should be " AND [tblNewCC].[Date] = #" & Me.cboDate.Value & "#" As an aside, 'Date' is a terrible name for a field. It is a reserved word in Access and will eventually cause you problems. Here is a helpful link http://www.fontstuff.com/access/acctut15pfv.htm
So I have two subforms, one to show internal training course completion for an employee and the other is the same thing but for vendor training.
Both subforms pull the same data from the same table, but display different selective data (different columns from the table).
I added the employee search combobox code to reflect the second "vendor training" subform:
Private Sub cboEmployee_AfterUpdate()
On Error GoTo Proc_Error
If IsNull(Me.cboEmployee) Then
Me.subEmployeeCourseTrainingCompletion.Form.Filter = ""
Me.subEmployeeCourseTrainingCompletion.Form.FilterOn = False
Me.subEmployeeVendorCourseTrainingCompletion.Form.Filter = ""
Me.subEmployeeVendorCourseTrainingCompletion.Form.FilterOn = False
Else
Me.subEmployeeCourseTrainingCompletion.Form.Filter = "[EmployeeID]=" & Me.cboEmployee
Me.subEmployeeCourseTrainingCompletion.Form.FilterOn = True
Debug.Print Me.subEmployeeCourseTrainingCompletion.Form.Filter
Me.subEmployeeVendorCourseTrainingCompletion.Form.Filter = "[EmployeeID]=" & Me.cboEmployee
Me.subEmployeeVendorCourseTrainingCompletion.Form.FilterOn = True
Debug.Print Me.subEmployeeVendorCourseTrainingCompletion.Form.Filter
End If
Proc_Exit:
Exit Sub
Proc_Error:
MsgBox "Error " & Err.Number & " in setting subEmployeeCourseTrainingCompletion filter:" & vbCrLf & Err.Description
MsgBox "Error " & Err.Number & " in setting subEmployeeVendorCourseTrainingCompletion filter:" & vbCrLf & Err.Description
Resume Proc_Exit
End Sub
The internval training subform still works and updates based on the employee ID in the combobox, but the second, vendor, subform doesn't update.
Any ideas as to why and possible solutions?
Force the update of the second form once you have made changes and saved the data in the first one:
Me.subEmployeeVendorCourseTrainingCompletion.Form.Requery
You could do this in the Form_AfterUpdate of the first subform:
Private Sub Form_AfterUpdate()
Parent.subEmployeeVendorCourseTrainingCompletion.Form.Requery
End Sub
UPDATE
Try another approach. Instead of setting filters use the Link Child Fields and Link Master Fields properties of the subforms in order to link the subforms to the main form.