473,386 Members | 1,708 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Form to add records to table

70 64KB
I'm building a form which first allows users to search for a customer by Last Name, First Name, Organization, Shop Name, or office symbol.

I then have five text boxes, each bound to their respective fields (lastname, firstname, etc). These display the result of the search form so that the user knows what customer they are viewing.

At which point, I have a combo box that allows a user to select a building name. Then there is an option group which allows the user to select if the customer is a Building Facility Manager (option 1) or a Room Point of Contact (option 2).

If they are a building facility manager, I need a button to appear (visibility = true) which says "add customer to building." I need to then take the customer ID (tblCustomer.CustomerPK) from the customer search form and the Building ID (tblBuilding.BuildingPK) from the building name combo box and I need to add those IDs into tblFacilityMgr. I have not worked with SQL insert, so this is confusing to me.

If they are a room point of contact, I need a list box to appear which displays the rooms within the building which was selected in cboBuildingName. Then they need to select one of the rooms in that list box. At which point, a button should appear that says "Add customer to room." Then, much like w/ facility managers, the customer ID and the room ID (tblRooms.RoomsPK) needs to be added into a junction table, tblRoomsPOC.

Attached is a photo of the form thus far. lstRoomsInBldg is hidden until someone selects a building name.

Here is the vba code that I have so far. I think if I could figure out how to add the values of the Customer ID (from results of search form) and building ID (from cboBuildingName) into the correct tabe, I could easily finish the rest of the form myself. I believe that would be INSERT INTO. I'd really appreciate it if someone at least pointed me in the right direction.

Expand|Select|Wrap|Line Numbers
  1. Option Compare Database
  2.  
  3. Private Sub Form_Load()
  4. 'make some things not visible on load
  5.  
  6.     Me.lstRoomsInBldg.Visible = False
  7.     'Me.RecCnt.Visible = False
  8.   '  Me.btnAssignPOC.Visible = False
  9. End Sub
  10. Private Sub cmdSearch_Click()
  11. Dim strWhere As String
  12.     Dim lngLen As Long
  13.     Dim startStr As String
  14.     If Not IsNullOrEmpty(Me.cboSearchLastName) Then
  15.         startStr = IIf(strWhere = "", "", " AND ")
  16.         strWhere = strWhere & startStr & "[LastName] ='" & Me.cboSearchLastName & "'"
  17.     End If
  18.     If Not IsNullOrEmpty(Me.cboSearchFirstName) Then
  19.         startStr = IIf(strWhere = "", "", " AND ")
  20.         strWhere = strWhere & startStr & "[FirstName] ='" & Me.cboSearchFirstName & "'"
  21.     End If
  22.     If Not IsNullOrEmpty(Me.cboSearchOrganization) Then
  23.         startStr = IIf(strWhere = "", "", " AND ")
  24.         strWhere = strWhere & startStr & "[OrganizationFK] =" & Me.cboSearchOrganization
  25.     End If
  26.     If Not IsNullOrEmpty(Me.cboSearchShopName) Then
  27.         startStr = IIf(strWhere = "", "", " AND ")
  28.         strWhere = strWhere & startStr & "[ShopNameFK] =" & Me.cboSearchShopName
  29.     End If
  30.     If Not IsNullOrEmpty(Me.cboSearchOfficeSym) Then
  31.         startStr = IIf(strWhere = "", "", " AND ")
  32.         strWhere = strWhere & startStr & "[OfficeSymFK] =" & Me.cboSearchOfficeSym
  33.     End If
  34.     Call MsgBox(strWhere, vbOKOnly, "Debug")
  35.         MsgBox strWhere
  36.          If DCount("*", "qryPopupAddCustomerToRoom", strWhere) = 0 Then
  37.                 MsgBox "No corresponding records to your search criteria." & vbCrLf & vbCrLf
  38.                 Me.FilterOn = False
  39.                 Me.cboSearchOrganization = ""
  40.                 Me.cboSearchShopName = ""
  41.                 Me.cboSearchOfficeSym = ""
  42.                 Me.cboSearchLastName = ""
  43.                 Me.cboSearchFirstName = ""
  44.          Else
  45.             Me.Filter = strWhere
  46.             Me.FilterOn = True
  47.         End If
  48.      If Me.Frame13 = 1 Then
  49.         MsgBox "Check to ensure a Lastname was selected, and a Building has been selected" & vbCrLf _
  50.                & "FacilityMgr selected:" & vbCrLf _
  51.                & "Assign FaciityMgr Role for this Bldg to this Customer" & vbCrLf _
  52.                & "Get all Rooms for the selected Bldg and assign this Customer as RoomPOC for each"
  53.  
  54.  
  55.     Else
  56.         Me.Frame13 = 2
  57.         MsgBox "RoomPOC selected:" & vbCrLf _
  58.                & " Get all Rooms for the selected Bldg '" & Me.cboBuildingName & "'" & vbCrLf _
  59.                & " Make Listbox of Rooms visible " & vbCrLf _
  60.                & " Select room(s) in Bldg and assign this Customer as RoomPOC for each selection"
  61.  
  62.         Debug.Print Me.cboBuildingName.Column(0)
  63.         Me.lstRoomsInBldg.RowSource = "SELECT RoomsPK,BuildingFK,RoomName,SecOptionFK from tblRooms where BuildingFK =" & Me.cboBuildingName.Column(0)
  64.         Me.lstRoomsInBldg.Visible = True
  65.      '   Me.btnAssignPOC.Visible = True
  66.         Me.Requery
  67.     End If
  68.  
  69. End Sub
  70.  
  71.  
  72.  
  73. Function IsNullOrEmpty(val As Variant) As Boolean
  74.    'First conditional validates for Nothing
  75.    'Second condition validates for an Empty String situation "" or "     "
  76.    Dim ret As Boolean: ret = False
  77.    If IsMissing(val) Then
  78.       ret = True
  79.    ElseIf (val Is Nothing) Then
  80.       ret = True
  81.    ElseIf (val & vbNullString = vbNullString) Then
  82.       ret = True
  83.    ElseIf (Len(Trim(val)) <= 0) Then
  84.       ret = True
  85.    End If
  86.  
  87.    IsNullOrEmpty = ret
  88. End Function
  89.  

Attached Images
File Type: jpg addcustomer.jpg (29.2 KB, 325 views)
Oct 12 '15 #1
1 1264
zmbd
5,501 Expert Mod 4TB
1) NZ() (click here) is your friend
Expand|Select|Wrap|Line Numbers
  1. if nz([controlname],"") & "" = "" then
  2.    ... true condition
  3. else
  4.    ... false condition code
  5.  
2) You have at least two questions here (maybe more?):
  1. ." I need to then take the customer ID (tblCustomer.CustomerPK) from the customer search form and the Building ID (tblBuilding.BuildingPK) from the building name combo box and I need to add those IDs into tblFacilityMgr (...)
  2. . If they are a room point of contact, I need a list box to appear which displays the rooms within the building which was selected in cboBuildingName(...)
So let's narrow this down to what you need first; however, before we start does the term "Normalization" (click here) mean anything to you as it relates to database design?
Oct 12 '15 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Colm O'Hagan | last post by:
Hi there, I having a problem with a database I'm setting up, I would be delighted if someone out there could help. The database I'm setting up is a task register datebase, it will be used to...
2
by: Bill Hand | last post by:
Is it possible to open a form from table and have it access a given record? I want to be able to query all baseball cards with the last name Jones and have it open a table. In each record of...
4
by: Jim | last post by:
I have a form that is using a query for the control source. The query put the data in order of TOP 20. I've added an extra textbox in the form and want to be able to automatically rank the records...
9
by: sck10 | last post by:
Hello, I am building a web form that will be used to gather information for marketing plans. The form will have 15 questions which must be answered. Each question can have large blocks of text....
3
by: KayC | last post by:
Hi Background info: I am running Access 2000 I have a form bound to a blank table When a user clicks a button the form opens in datasheet view User enters data into form and closes form User...
0
by: abhishekjethwani | last post by:
How to write a query to access tree structure form multi table. I m having five tables from them first table give me a data which act as the parameter for query for the second table and the two...
3
by: abie16 | last post by:
I'm creating a database for my company. Here we have errors form to calculate the errors done. The data entered in this form need to update into the errors table. This is my code but i'm getting...
4
by: novoselent | last post by:
This seems like it should be an easy thing, but I think I'm missing something simple here...or I'm just going about it all wrong... Using Access 2003 I have a form that lists vehicle service...
6
by: BEETHOVEN | last post by:
I have an option group called Issue_Type on my main form F1_Member_Demographics_Main. When I select one of the 3 options on the main form from the option group Issue_Type I want to limit the sub...
1
by: xraive | last post by:
I have a problem with this. Currently I am trying Allen's code and i am not successful. Current Design Table1 (Main Form) TravelID (PK) ApprovedBY EntreredBy BudgetCode ExpenseCode
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.